From e739e019003ae67da328f51757e103b1fedf451f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 12 Mar 2014 12:49:34 +0100 Subject: [PATCH] core: use ASSERT_VALID_PATH_COMPONENT Signed-off-by: Thomas Haller --- src/NetworkManagerUtils.c | 3 +++ src/devices/adsl/nm-device-adsl.c | 6 ++++-- src/devices/nm-device-infiniband.c | 6 ++++-- src/devices/nm-device-wifi.c | 2 +- src/platform/nm-linux-platform.c | 10 ++++++++-- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 553dfc5262..0fc35c2d96 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -1046,6 +1046,9 @@ nm_utils_ip6_property_path (const char *ifname, const char *property) static char path[sizeof (IPV6_PROPERTY_DIR) + IFNAMSIZ + 32]; int len; + ifname = ASSERT_VALID_PATH_COMPONENT (ifname); + property = ASSERT_VALID_PATH_COMPONENT (property); + len = g_snprintf (path, sizeof (path), IPV6_PROPERTY_DIR "%s/%s", ifname, property); g_assert (len < sizeof (path) - 1); diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index 7fe626e7ca..2ba364e4d1 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -538,7 +538,8 @@ carrier_update_cb (gpointer user_data) iface = nm_device_get_iface (NM_DEVICE (self)); - path = g_strdup_printf ("/sys/class/atm/%s/carrier", iface); + path = g_strdup_printf ("/sys/class/atm/%s/carrier", + ASSERT_VALID_PATH_COMPONENT (iface)); success = g_file_get_contents (path, &contents, NULL, &error); g_free (path); @@ -581,7 +582,8 @@ get_atm_index (const char *iface, GError **error) char *path, *contents; int idx = -1; - path = g_strdup_printf ("/sys/class/atm/%s/atmindex", iface); + path = g_strdup_printf ("/sys/class/atm/%s/atmindex", + ASSERT_VALID_PATH_COMPONENT (iface)); if (g_file_get_contents (path, &contents, NULL, error)) idx = atoi (contents); g_free (path); diff --git a/src/devices/nm-device-infiniband.c b/src/devices/nm-device-infiniband.c index be79094c07..1bc3d5edfc 100644 --- a/src/devices/nm-device-infiniband.c +++ b/src/devices/nm-device-infiniband.c @@ -168,7 +168,8 @@ act_stage1_prepare (NMDevice *dev, NMDeviceStateReason *reason) transport_mode = nm_setting_infiniband_get_transport_mode (s_infiniband); - mode_path = g_strdup_printf ("/sys/class/net/%s/mode", nm_device_get_iface (dev)); + mode_path = g_strdup_printf ("/sys/class/net/%s/mode", + ASSERT_VALID_PATH_COMPONENT (nm_device_get_iface (dev))); if (!g_file_test (mode_path, G_FILE_TEST_EXISTS)) { g_free (mode_path); @@ -327,7 +328,8 @@ update_connection (NMDevice *device, NMConnection *connection) g_byte_array_unref (array); } - mode_path = g_strdup_printf ("/sys/class/net/%s/mode", nm_device_get_iface (device)); + mode_path = g_strdup_printf ("/sys/class/net/%s/mode", + ASSERT_VALID_PATH_COMPONENT (nm_device_get_iface (device))); if (g_file_get_contents (mode_path, &contents, NULL, NULL)) { if (strstr (contents, "datagram")) transport_mode = "datagram"; diff --git a/src/devices/nm-device-wifi.c b/src/devices/nm-device-wifi.c index d5398773ba..9da7468e31 100644 --- a/src/devices/nm-device-wifi.c +++ b/src/devices/nm-device-wifi.c @@ -331,7 +331,7 @@ constructor (GType type, * don't have to poll. */ priv->ipw_rfkill_path = g_strdup_printf ("/sys/class/net/%s/device/rf_kill", - nm_device_get_iface (NM_DEVICE (self))); + ASSERT_VALID_PATH_COMPONENT (nm_device_get_iface (NM_DEVICE (self)))); if (!g_file_test (priv->ipw_rfkill_path, G_FILE_TEST_IS_REGULAR)) { g_free (priv->ipw_rfkill_path); priv->ipw_rfkill_path = NULL; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 57977f1cad..edc8fe4143 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -2153,6 +2153,8 @@ link_get_physical_port_id (NMPlatform *platform, int ifindex) if (!ifname) return NULL; + ifname = ASSERT_VALID_PATH_COMPONENT (ifname); + path = g_strdup_printf ("/sys/class/net/%s/phys_port_id", ifname); id = sysctl_get (platform, path); g_free (path); @@ -2266,7 +2268,10 @@ link_option_path (int master, const char *category, const char *option) if (!name || !category || !option) return NULL; - return g_strdup_printf ("/sys/class/net/%s/%s/%s", name, category, option); + return g_strdup_printf ("/sys/class/net/%s/%s/%s", + ASSERT_VALID_PATH_COMPONENT (name), + ASSERT_VALID_PATH_COMPONENT (category), + ASSERT_VALID_PATH_COMPONENT (option)); } static gboolean @@ -2352,7 +2357,7 @@ infiniband_partition_add (NMPlatform *platform, int parent, int p_key) parent_name = nm_platform_link_get_name (parent); g_return_val_if_fail (parent_name != NULL, FALSE); - path = g_strdup_printf ("/sys/class/net/%s/create_child", parent_name); + path = g_strdup_printf ("/sys/class/net/%s/create_child", ASSERT_VALID_PATH_COMPONENT (parent_name)); id = g_strdup_printf ("0x%04x", p_key); success = nm_platform_sysctl_set (path, id); g_free (id); @@ -2412,6 +2417,7 @@ tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties * ifname = nm_platform_link_get_name (ifindex); if (!ifname || !nm_utils_iface_valid_name (ifname)) return FALSE; + ifname = ASSERT_VALID_PATH_COMPONENT (ifname); path = g_strdup_printf ("/sys/class/net/%s/owner", ifname); val = nm_platform_sysctl_get (path);