Message ID | 20200911131528.19734-1-jgross@suse.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | tools/libs/stat: fix broken build | expand |
On Fri, Sep 11, 2020 at 03:15:28PM +0200, Juergen Gross wrote: > 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. > Signed-off-by: Juergen Gross <jgross@suse.com> > --- > 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 >
On 11/09/2020 18:58, Wei Liu wrote: > On Fri, Sep 11, 2020 at 03:15:28PM +0200, Juergen Gross wrote: >> 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. 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
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) {
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@suse.com> --- tools/libs/stat/xenstat_linux.c | 6 ++++++ 1 file changed, 6 insertions(+)