From daaa741a3d4bddcfd01715fd6caf7d0c84107a6d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 26 Apr 2017 21:49:22 +0200 Subject: [PATCH] ifcfg-rh: treat a wrongly quoted value like empty string For example, if you want to test whether a value is present and reset it to a different value (only if it is present), it would be reasonable to do if (svGetValue (s, key, &tmp)) { svSetValue (s, key, "new-value"); g_free (tmp); } Without this patch, you could not be sure that key is not set to some inparsable value, which svWriteFile() would then write out as empty string. Have invalid values returned by svGetValue() as empty string. That is how svWriteFile() treats them. --- src/settings/plugins/ifcfg-rh/shvar.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index d847ba73f0..25a012cf3c 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -897,8 +897,19 @@ _svGetValue (shvarFile *s, const char *key, char **to_free) } if (last) { line = last->data; - if (line->line) - return svUnescape (line->line, to_free); + if (line->line) { + const char *v; + + v = svUnescape (line->line, to_free); + if (!v) { + /* a wrongly quoted value is treated like the empty string. + * See also svWriteFile(), which handles unparsable values + * that way. */ + nm_assert (!*to_free); + return ""; + } + return v; + } } *to_free = NULL; return NULL;