dispatcher: extra sanitize names of environment variables

The DHCP options should already be sanitized. Still, make sure we don't
create a bogus environment.
This commit is contained in:
Thomas Haller 2018-05-16 08:46:52 +02:00
parent 009b7d61ad
commit c86d0b4722

View file

@ -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);