From 8d2ceac897ca3cc9b60985cc39714650da0b3443 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. (cherry picked from commit 6470bed5f1ad25e20df14b333f1b083c9b390ece) --- 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;