]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
tools: libxenstat: fix format string overflow
authorDario Faggioli <dfaggioli@suse.com>
Fri, 16 Feb 2018 18:38:48 +0000 (19:38 +0100)
committerWei Liu <wei.liu2@citrix.com>
Mon, 19 Feb 2018 17:04:43 +0000 (17:04 +0000)
With gcc 7.3.0, the build fails like this:

src/xenstat_linux.c: In function ‘getBridge’
src/xenstat_linux.c:78:34: warning: ‘%s’ directive writing up to 255 bytes into a region of size 241 [-Wformat-overflow=]
     sprintf(tmp, "/sys/class/net/%s/bridge", de->d_name);
                                  ^~
src/xenstat_linux.c:78:5: note: ‘sprintf’ output between 23 and 278 bytes into a destination of size 256
     sprintf(tmp, "/sys/class/net/%s/bridge", de->d_name);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix by making the buffer bigger.

Signed-off-by: Dario Faggioli <dfaggioli@suse.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/xenstat/libxenstat/src/xenstat_linux.c

index 907d65fa6386a06f2824067125ec897953798168..7cdd3bf91fa034f0cdf48fe4e65612dabf967298 100644 (file)
@@ -69,7 +69,7 @@ void getBridge(char *excludeName, char *result, size_t resultLen)
        struct dirent *de;
        DIR *d;
 
-       char tmp[256] = { 0 };
+       char tmp[512] = { 0 };
 
        d = opendir("/sys/class/net");
        while ((de = readdir(d)) != NULL) {