[dm-devel] [PATCH] multipathd: fix issue in 'map $map getprstatus' reply

peng.liang5 at zte.com.cn peng.liang5 at zte.com.cn
Wed Aug 3 07:00:04 UTC 2016


Hi Bart,

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

diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
index 0b04504..cec40eb 100644
--- a/multipathd/cli_handlers.c
+++ b/multipathd/cli_handlers.c
@@ -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 <bart.vanassche at sandisk.com>
收件人:         <peng.liang5 at zte.com.cn>, christophe varoqui 
<christophe.varoqui at free.fr>, 
抄送:   <zhang.kai16 at zte.com.cn>, <dm-devel at redhat.com>
日期:   2016/08/02 23:20
主题:   Re: [dm-devel] [PATCH] multipathd: fix issue in 'map $map 
getprstatus' reply



On 08/01/2016 06:27 PM, peng.liang5 at zte.com.cn wrote:
> From: peng liang <peng.liang5 at zte.com.cn>
>
> add missing newline to 'map|multipath $map getprstatus' reply
>
> Signed-off-by: peng liang <peng.liang5 at zte.com.cn>
> ---
>  multipathd/cli_handlers.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/multipathd/cli_handlers.c b/multipathd/cli_handlers.c
> index 8ff4362..0b04504 100644
> --- a/multipathd/cli_handlers.c
> +++ b/multipathd/cli_handlers.c
> @@ -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';

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.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/dm-devel/attachments/20160803/ef2f5ded/attachment.htm>


More information about the dm-devel mailing list