summaryrefslogtreecommitdiff
path: root/dispatcher
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-05-16 08:46:52 +0200
committerThomas Haller <thaller@redhat.com>2018-05-16 08:46:52 +0200
commitc86d0b47229c036e1c1c39e81d7d125dcd8e74b9 (patch)
tree109e4dcb2053dc095fe953df63dfd2e8e5d71156 /dispatcher
parent009b7d61ad5679e405483973d843660d3d7a19d6 (diff)
downloadNetworkManager-c86d0b47229c036e1c1c39e81d7d125dcd8e74b9.tar.gz
dispatcher: extra sanitize names of environment variables
The DHCP options should already be sanitized. Still, make sure we don't create a bogus environment.
Diffstat (limited to 'dispatcher')
-rw-r--r--dispatcher/nm-dispatcher-utils.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/dispatcher/nm-dispatcher-utils.c b/dispatcher/nm-dispatcher-utils.c
index 5e090e2c28..db4d99343c 100644
--- a/dispatcher/nm-dispatcher-utils.c
+++ b/dispatcher/nm-dispatcher-utils.c
@@ -33,6 +33,26 @@
#include "nm-dispatcher-utils.h"
+static char *
+_validate_var_name (const char *key)
+{
+ char *sanitized = NULL;
+ nm_assert (key);
+
+ if (!key[0])
+ return NULL;
+
+ sanitized = g_ascii_strup (key, -1);
+ if (!NM_STRCHAR_ALL (sanitized, ch, (ch >= 'A' && ch <= 'Z')
+ || (ch >= '0' && ch <= '9')
+ || NM_IN_SET (ch, '_'))) {
+ g_free (sanitized);
+ return NULL;
+ }
+
+ return sanitized;
+}
+
static GSList *
construct_basic_items (GSList *list,
const char *uuid,
@@ -244,7 +264,9 @@ construct_device_dhcp4_items (GSList *items, GVariant *dhcp4_config)
g_variant_iter_init (&iter, dhcp4_config);
while (g_variant_iter_next (&iter, "{&sv}", &key, &val)) {
- ucased = g_ascii_strup (key, -1);
+ ucased = _validate_var_name (key);
+ if (!ucased)
+ continue;
tmp = g_variant_get_string (val, NULL);
items = g_slist_prepend (items, g_strdup_printf ("DHCP4_%s=%s", ucased, tmp));
g_free (ucased);
@@ -349,7 +371,9 @@ construct_device_dhcp6_items (GSList *items, GVariant *dhcp6_config)
g_variant_iter_init (&iter, dhcp6_config);
while (g_variant_iter_next (&iter, "{&sv}", &key, &val)) {
- ucased = g_ascii_strup (key, -1);
+ ucased = _validate_var_name (key);
+ if (!ucased)
+ continue;
tmp = g_variant_get_string (val, NULL);
items = g_slist_prepend (items, g_strdup_printf ("DHCP6_%s=%s", ucased, tmp));
g_free (ucased);