[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tools/libs/stat: fix broken build



Making getBridge() static triggered a build error with some gcc versions:

error: 'strncpy' output may be truncated copying 15 bytes from a string of
length 255 [-Werror=stringop-truncation]

Fix that by printing a sane error message and bailing out in case the name of
a bridge is too long.

Fixes: 6d0ec053907794 ("tools: split libxenstat into new tools/libs/stat 
directory")
Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
 tools/libs/stat/xenstat_linux.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/libs/stat/xenstat_linux.c b/tools/libs/stat/xenstat_linux.c
index 793263f2b6..ce38b3433f 100644
--- a/tools/libs/stat/xenstat_linux.c
+++ b/tools/libs/stat/xenstat_linux.c
@@ -75,6 +75,12 @@ static void getBridge(char *excludeName, char *result, 
size_t resultLen)
        while ((de = readdir(d)) != NULL) {
                if ((strlen(de->d_name) > 0) && (de->d_name[0] != '.')
                        && (strstr(de->d_name, excludeName) == NULL)) {
+                               if (strlen(de->d_name) > resultLen - 1) {
+                                       fprintf(stderr,
+                                               "bridge name %s too long\n",
+                                               de->d_name);
+                                       break;
+                               }
                                sprintf(tmp, "/sys/class/net/%s/bridge", 
de->d_name);
 
                                if (access(tmp, F_OK) == 0) {
-- 
2.26.2




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.