From: Stephen Hemminger Date: Sun, 29 Nov 2020 17:43:48 +0000 (-0800) Subject: misc: fix compiler warning in ifstat and nstat X-Git-Tag: v5.10.0~6^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c014983921389dc7880dfe368eb43cb2570f6a4b;p=thirdparty%2Fiproute2.git misc: fix compiler warning in ifstat and nstat The code here was doing strncpy() in a way that causes gcc 10 warning about possible string overflow. Just use strlcpy() which will null terminate and bound the string as expected. This has existed since start of git era so no Fixes tag. Signed-off-by: Stephen Hemminger --- diff --git a/misc/ifstat.c b/misc/ifstat.c index c05183d79..d4a33429d 100644 --- a/misc/ifstat.c +++ b/misc/ifstat.c @@ -251,7 +251,7 @@ static void load_raw_table(FILE *fp) buf[strlen(buf)-1] = 0; if (info_source[0] && strcmp(info_source, buf+1)) source_mismatch = 1; - strncpy(info_source, buf+1, sizeof(info_source)-1); + strlcpy(info_source, buf+1, sizeof(info_source)); continue; } if ((n = malloc(sizeof(*n))) == NULL) diff --git a/misc/nstat.c b/misc/nstat.c index 6fdd316cc..ecdd4ce82 100644 --- a/misc/nstat.c +++ b/misc/nstat.c @@ -136,8 +136,7 @@ static void load_good_table(FILE *fp) buf[strlen(buf)-1] = 0; if (info_source[0] && strcmp(info_source, buf+1)) source_mismatch = 1; - info_source[0] = 0; - strncat(info_source, buf+1, sizeof(info_source)-1); + strlcpy(info_source, buf + 1, sizeof(info_source)); continue; } /* idbuf is as big as buf, so this is safe */