summaryrefslogtreecommitdiff
path: root/src/platform/nm-platform-utils.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-03-07 11:11:59 +0100
committerThomas Haller <thaller@redhat.com>2016-03-07 11:36:57 +0100
commit0e90f1ba83c4204cad1da6d96e00e99f8c168534 (patch)
tree0a410bea061ac6627257be463f6850ae8e82b0bc /src/platform/nm-platform-utils.c
parent1dbe1d70df6d7f34d5ae636f30859d438d917a18 (diff)
downloadNetworkManager-0e90f1ba83c4204cad1da6d96e00e99f8c168534.tar.gz
platform: add and use nm_utils_ifname_cpy() helper
Coverity complains rightly about "strncpy (dst, ifname, IFNAMSIZ)" because it might leave @dst non-NULL-terminated, in case @ifname is too long (which already would be a bug in the first place). Replace the strcpy() uses by a new helper nm_utils_ifname_cpy() that asserts against valid arguments.
Diffstat (limited to 'src/platform/nm-platform-utils.c')
-rw-r--r--src/platform/nm-platform-utils.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c
index 0f2656f238..6020a8f3be 100644
--- a/src/platform/nm-platform-utils.c
+++ b/src/platform/nm-platform-utils.c
@@ -56,7 +56,7 @@ ethtool_get (const char *name, gpointer edata)
nm_assert (strlen (name) < IFNAMSIZ);
memset (&ifr, 0, sizeof (ifr));
- strcpy (ifr.ifr_name, name);
+ nm_utils_ifname_cpy (ifr.ifr_name, name);
ifr.ifr_data = edata;
fd = socket (PF_INET, SOCK_DGRAM, 0);
@@ -344,7 +344,7 @@ nmp_utils_mii_supports_carrier_detect (const char *ifname)
}
memset (&ifr, 0, sizeof (struct ifreq));
- strncpy (ifr.ifr_name, ifname, IFNAMSIZ);
+ nm_utils_ifname_cpy (ifr.ifr_name, ifname);
errno = 0;
if (ioctl (fd, SIOCGMIIPHY, &ifr) < 0) {
@@ -513,13 +513,14 @@ gboolean
nmp_utils_device_exists (const char *name)
{
#define SYS_CLASS_NET "/sys/class/net/"
- char sysdir[NM_STRLEN (SYS_CLASS_NET) + IFNAMSIZ] = SYS_CLASS_NET;
+ char sysdir[NM_STRLEN (SYS_CLASS_NET) + IFNAMSIZ];
if ( !name
|| strlen (name) >= IFNAMSIZ
|| !nm_utils_is_valid_path_component (name))
g_return_val_if_reached (FALSE);
- strcpy (&sysdir[NM_STRLEN (SYS_CLASS_NET)], name);
+ memcpy (sysdir, SYS_CLASS_NET, NM_STRLEN (SYS_CLASS_NET));
+ nm_utils_ifname_cpy (&sysdir[NM_STRLEN (SYS_CLASS_NET)], name);
return g_file_test (sysdir, G_FILE_TEST_EXISTS);
}