]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
misc: fix compiler warning in ifstat and nstat
authorStephen Hemminger <stephen@networkplumber.org>
Sun, 29 Nov 2020 17:43:48 +0000 (09:43 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 30 Nov 2020 00:20:31 +0000 (16:20 -0800)
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 <stephen@networkplumber.org>
misc/ifstat.c
misc/nstat.c

index c05183d79a13aedaf17812aad46085b8dcd257a1..d4a33429dc507b37743841e321ca2e40aac113ed 100644 (file)
@@ -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)
index 6fdd316cce849d48e14d2f8c44e9a538ee193ef9..ecdd4ce8266db0aa3825f2bd39986bc186ff846e 100644 (file)
@@ -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 */