multipath: Fix a potential buffer overflow
authorBart Van Assche <bart.vanassche@sandisk.com>
Tue, 13 Jun 2017 16:33:39 +0000 (09:33 -0700)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Wed, 21 Jun 2017 10:14:41 +0000 (12:14 +0200)
Avoid that gcc 7 reports the following warning:

cli_handlers.c:1340:18: warning: '%d' directive writing between 1 and 3 bytes into a region of size 2 [-Wformat-overflow=]
  sprintf(*reply,"%d",mpp->prflag);

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
multipathd/cli_handlers.c

index 7b0d00c..b4a95e3 100644 (file)
@@ -1,6 +1,9 @@
 /*
  * Copyright (c) 2005 Christophe Varoqui
  */
+
+#define _GNU_SOURCE
+
 #include "checkers.h"
 #include "memory.h"
 #include "vector.h"
@@ -1334,14 +1337,9 @@ 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);
-
-
-       sprintf(*reply,"%d",mpp->prflag);
-       (*reply)[1]='\0';
-
+       *len = asprintf(reply, "%d", mpp->prflag);
+       if (*len < 0)
+               return 1;
 
        condlog(3, "%s: reply = %s", param, *reply);