summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-04-21 11:10:13 +0200
committerThomas Haller <thaller@redhat.com>2016-04-21 15:02:22 +0200
commitaa509fd8fe9347244947e45070ef84d05b5bd8e3 (patch)
treec3ea26f1c79e900fcb279e75f3660a95f844958b
parentc486c38962a68bbf99a22ce0dae55678b79c6605 (diff)
downloadNetworkManager-aa509fd8fe9347244947e45070ef84d05b5bd8e3.tar.gz
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.
-rw-r--r--src/platform/nm-linux-platform.c11
1 files 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) {