From 5b123f2539ec11cd34e75bac7bbfe0738dac0925 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 3 Jul 2015 09:53:34 +0200 Subject: [PATCH] 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. --- src/platform/nm-platform-utils.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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);