From c87433ebd2f349ce78e3a32e244b462a358f6347 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 8 Jun 2021 13:26:19 +0200 Subject: [PATCH] platform: avoid wrong coverity warning in nmp_utils_sysctl_open_netdir() The warning is wrong, because we already assert for the string length a few lines earlier. Error: STRING_OVERFLOW (CWE-120): [#def595] NetworkManager-1.31.90/src/libnm-platform/nm-platform-utils.c:1896: fixed_size_dest: You might overrun the 16-character fixed-size string "ifname_buf_last_try" by copying "ifname" without checking the length. # 1894| if (nm_streq(ifname, ifname_buf_last_try)) # 1895| return -1; # 1896|-> strcpy(ifname_buf_last_try, ifname); # 1897| # 1898| fd_dir = open(sysdir, O_DIRECTORY | O_CLOEXEC); --- src/libnm-platform/nm-platform-utils.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libnm-platform/nm-platform-utils.c b/src/libnm-platform/nm-platform-utils.c index 6435dcc482..2470704a6f 100644 --- a/src/libnm-platform/nm-platform-utils.c +++ b/src/libnm-platform/nm-platform-utils.c @@ -1893,7 +1893,9 @@ nmp_utils_sysctl_open_netdir(int ifindex, const char *ifname_guess, char *out_if * end of the @try_count. */ if (nm_streq(ifname, ifname_buf_last_try)) return -1; - strcpy(ifname_buf_last_try, ifname); + + if (g_strlcpy(ifname_buf_last_try, ifname, IFNAMSIZ) >= IFNAMSIZ) + nm_assert_not_reached(); fd_dir = open(sysdir, O_DIRECTORY | O_CLOEXEC); if (fd_dir < 0)