mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 20:00:09 +01:00
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:
parent
cfd8cf54df
commit
8d2ceac897
1 changed files with 13 additions and 2 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue