diff options
author | Thomas Haller <thaller@redhat.com> | 2017-04-26 21:49:22 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2017-04-27 17:24:23 +0200 |
commit | daaa741a3d4bddcfd01715fd6caf7d0c84107a6d (patch) | |
tree | d30fb4921de0e9c53b94e87cf52f8e129d461165 | |
parent | 39594852ba0e6da7ab6c9ae8a1e23d38b69ff307 (diff) | |
download | NetworkManager-daaa741a3d4bddcfd01715fd6caf7d0c84107a6d.tar.gz |
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.
-rw-r--r-- | src/settings/plugins/ifcfg-rh/shvar.c | 15 |
1 files 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; |