From aa509fd8fe9347244947e45070ef84d05b5bd8e3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 21 Apr 2016 11:10:13 +0200 Subject: platform: stack-allocate temporary string in _linktype_read_devtype() And while at it, don't pass the sysfs_path but instead the ifname to it. --- src/platform/nm-linux-platform.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 1ce4818a13..f1f4edac9c 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -593,12 +593,17 @@ _lookup_cached_link (const NMPCache *cache, int ifindex, gboolean *completed_fro #define DEVTYPE_PREFIX "DEVTYPE=" static char * -_linktype_read_devtype (const char *sysfs_path) +_linktype_read_devtype (const char *ifname) { - gs_free char *uevent = g_strdup_printf ("%s/uevent", sysfs_path); + char uevent[NM_STRLEN ("/sys/class/net/123456789012345/uevent\0") + 100 /*safety*/]; char *contents = NULL; char *cont, *end; + nm_sprintf_buf (uevent, + "/sys/class/net/%s/uevent", + NM_ASSERT_VALID_PATH_COMPONENT (ifname)); + nm_assert (strlen (uevent) < sizeof (uevent) - 1); + if (!g_file_get_contents (uevent, &contents, NULL, NULL)) return NULL; for (cont = contents; cont; cont = end) { @@ -716,7 +721,7 @@ _linktype_get_type (NMPlatform *platform, if (g_file_test (anycast_mask, G_FILE_TEST_EXISTS)) return NM_LINK_TYPE_OLPC_MESH; - devtype = _linktype_read_devtype (sysfs_path); + devtype = _linktype_read_devtype (ifname); for (i = 0; devtype && i < G_N_ELEMENTS (linktypes); i++) { if (g_strcmp0 (devtype, linktypes[i].devtype) == 0) { if (linktypes[i].nm_type == NM_LINK_TYPE_BNEP) { -- cgit v1.2.1