summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-07-03 09:53:34 +0200
committerThomas Haller <thaller@redhat.com>2015-07-12 13:56:52 +0200
commit5b123f2539ec11cd34e75bac7bbfe0738dac0925 (patch)
tree05addeeb0d4a252c4ca2236edd7adde12fad965b
parent904e9614641fe8203a5f61abaa841b7d186a343b (diff)
downloadNetworkManager-5b123f2539ec11cd34e75bac7bbfe0738dac0925.tar.gz
platform: assert for valid ifname in ethtool_get()
Add an assert (g_return_val_if_reached()) that the interface name is valid and shorter then 16 bytes. If it happened to be longer, strncpy() would not have zero terminated the interface name.
-rw-r--r--src/platform/nm-platform-utils.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c
index d3c62bddcd..2d064e1dd3 100644
--- a/src/platform/nm-platform-utils.c
+++ b/src/platform/nm-platform-utils.c
@@ -48,8 +48,11 @@ ethtool_get (const char *name, gpointer edata)
if (!name || !*name)
return FALSE;
+ if (strlen (name) >= IFNAMSIZ)
+ g_return_val_if_reached (FALSE);
+
memset (&ifr, 0, sizeof (ifr));
- strncpy (ifr.ifr_name, name, IFNAMSIZ);
+ strcpy (ifr.ifr_name, name);
ifr.ifr_data = edata;
fd = socket (PF_INET, SOCK_DGRAM, 0);