From afc394b969fac882066eedb0876f680ee52183ee Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 14:44:31 +0100 Subject: [PATCH] ifcfg-rh: assert that keys are valid shell names --- src/settings/plugins/ifcfg-rh/shvar.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index e727e0a7a2..88e57015b9 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -85,6 +85,21 @@ svParseBoolean (const char *value, gint fallback) /*****************************************************************************/ +static gboolean +_shell_is_name (const char *key) +{ + /* whether @key is a valid identifier (name). */ + if (!key) + return FALSE; + if ( !g_ascii_isalpha (key[0]) + && key[0] != '_') + return FALSE; + return NM_STRCHAR_ALL (&key[1], ch, + g_ascii_isalnum (ch) || ch == '_'); +} + +/*****************************************************************************/ + #define ESC_ESCAPEES "\"'\\$~`" /* must be escaped */ #define ESC_SPACES " \t|&;()<>" /* only require "" */ #define ESC_NEWLINES "\n\r" /* will be removed */ @@ -312,6 +327,8 @@ find_line (shvarFile *s, const char *key) const char *line; gsize len; + nm_assert (_shell_is_name (key)); + len = strlen (key); for (s->current = s->lineList; s->current; s->current = s->current->next) {