summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);