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)
This commit is contained in:
Thomas Haller 2017-04-26 21:49:22 +02:00 committed by Lubomir Rintel
parent cfd8cf54df
commit 8d2ceac897

View file

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