tools/libs/stat: fix broken build
PATCH 1/1 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.
--- tools/libs/stat/xenstat_linux.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/libs/stat/xenstat_linux.c +6 -0
@@ -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 ) {
Signature · 1 line
2.26.2
Quoted 9 lines · Juergen Gross
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")
But this patch is not the one that created the bug though? It just happens to be the last patch that touched that file.
Quoted 25 lines
Signed-off-by Juergen Gross <[email protected]>--- tools/libs/stat/xenstat_linux.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/libs/stat/xenstat_linux.c +6
-0@@ -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 ) {Signature · 1 line
2.26.2
Quoted 6 lines · Wei Liu
Quoted 5 lines · Juergen Gross
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]
Quoted 6 lines
Quoted 4 lines
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")But this patch is not the one that created the bug though? It just happens to be the last patch that touched that file.
It "created" the bug by making getBridge() static, and therefore inlined into its sole caller, and therefore able to be analysed in this way by the compiler.
That said, Gitlab CI says no to this as a viable bugfix.
~Andrew