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
>