Skip to contentSkip to conversation

multipathd: fix issue in 'map $map getprstatus' reply

PATCH In review [email protected] 2 participants 3 messages Aug 2, 2016 – Aug 3, 2016 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 multipathd: fix issue in 'map $map getprstatus' reply

From: peng liang <[email protected]>

add missing newline to 'map|multipath $map getprstatus' reply

---
 multipathd/cli_handlers.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
multipathd/cli_handlers.c +5 -5
index 8ff4362..0b04504 100644
@@ -1285,13 +1285,13 @@ cli_getprstatus (void * v, char ** reply, int * len, void * data)
 
 	condlog(3, "%s: prflag = %u", param, (unsigned int)mpp->prflag);
 
-	*reply =(char *)malloc(2);
-	*len = 2;
-	memset(*reply,0,2);
+	*reply =(char *)malloc(3);
+	*len = 3;
+	memset(*reply,0,3);
 
 
-	sprintf(*reply,"%d",mpp->prflag);
-	(*reply)[1]='\0';
+	sprintf(*reply,"%d\n",mpp->prflag);
+	(*reply)[2]='\0';
 
 
 	condlog(3, "%s: reply = %s", param, *reply);
Signature · 1 line
2.8.1.windows.1
#1 lore raw
Quoted 19 lines · On 08/01/2016 06:27 PM, [email protected] wrote:

From: peng liang <[email protected]>

add missing newline to 'map|multipath $map getprstatus' reply

---
 multipathd/cli_handlers.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
multipathd/cli_handlers.c +0 -2
index 8ff4362..0b04504 100644
@@ -1285,13 +1285,13 @@ cli_getprstatus (void * v, char ** reply, int * len, void * data)
 
 	condlog(3, "%s: prflag = %u", param, (unsigned int)mpp->prflag);
 
-	*reply =(char *)malloc(2);
-	*len = 2;

multipathd/cli_handlers.c cli_getprstatus (void * v, char ** reply, int * len, void * data) · line 1294

Quoted 10 lines
multipathd/cli_handlers.c +5 -3
-	memset(*reply,0,2);
+	*reply =(char *)malloc(3);
+	*len = 3;
+	memset(*reply,0,3);
 
 
-	sprintf(*reply,"%d",mpp->prflag);
-	(*reply)[1]='\0';
+	sprintf(*reply,"%d\n",mpp->prflag);
+	(*reply)[2]='\0';

Hello Peng,

Please use asprintf() instead of malloc() + memset() + sprintf(). See also https://www.gnu.org/software/libc/manual/html_node/Dynamic-Output.html

Thanks,

Bart.

#2 lore raw

Hi Bart,

Thanks for your advice!
I have updated the solution as follows.

multipathd/cli_handlers.c +3 -0
index 0b04504..cec40eb 100644
@@ -1,6 +1,9 @@
 /*
  * Copyright (c) 2005 Christophe Varoqui
  */
+#define _GNU_SOURCE
+
+#include <stdio.h>
 #include "checkers.h"
 #include "memory.h"
 #include "vector.h"
@@ -1285,14 +1288,8 @@ cli_getprstatus (void * v, char ** reply, int * 

len, void * data)

        condlog(3, "%s: prflag = %u", param, (unsigned int)mpp->prflag);
-       *reply =(char *)malloc(3);
        *len = 3;

- memset(*reply,0,3);
-
-
- sprintf(*reply,"%d\n",mpp->prflag);
- (*reply)[2]='\0';
-
+ asprintf(reply, "%d\n", mpp->prflag);

        condlog(3, "%s: reply = %s", param, *reply); 

发件人: Bart Van Assche <[email protected]>
收件人: <[email protected]>, christophe varoqui
<[email protected]>,

抄送:   <[email protected]>, <[email protected]>
日期:   2016/08/02 23:20
主题:   Re: [dm-devel] [PATCH] multipathd: fix issue in 'map $map 

getprstatus' reply

multipathd/cli_handlers.c cli_getprstatus (void * v, char ** reply, int *

Quoted 14 lines · On 08/01/2016 06:27 PM, [email protected] wrote:

From: peng liang <[email protected]>

add missing newline to 'map|multipath $map getprstatus' reply

---
 multipathd/cli_handlers.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
multipathd/cli_handlers.c +0 -0
index 8ff4362..0b04504 100644
@@ -1285,13 +1285,13 @@ cli_getprstatus (void * v, char ** reply, int * 

len, void * data)

multipathd/cli_handlers.c cli_getprstatus (void * v, char ** reply, int * · line 1285

Quoted 2 lines
multipathd/cli_handlers.c +0 -0
               condlog(3, "%s: prflag = %u", param, (unsigned 

int)mpp->prflag);

multipathd/cli_handlers.c cli_getprstatus (void * v, char ** reply, int * · line 1292

Quoted 13 lines
multipathd/cli_handlers.c +5 -5
-              *reply =(char *)malloc(2);
-              *len = 2;
-              memset(*reply,0,2);
+              *reply =(char *)malloc(3);
+              *len = 3;
+              memset(*reply,0,3);
 
 
-              sprintf(*reply,"%d",mpp->prflag);
-              (*reply)[1]='\0';
+              sprintf(*reply,"%d\n",mpp->prflag);
+              (*reply)[2]='\0';

Hello Peng,

Please use asprintf() instead of malloc() + memset() + sprintf(). See also
https://www.gnu.org/software/libc/manual/html_node/Dynamic-Output.html

Thanks,

Bart.