Previously, the code could call g_strstrip(NULL) if a line started with
a quotation mark but didn’t end with one, e.g.:
MyKey="some-unbalanced-value
The code now ignores unbalanced quotation marks, returning the odd one
in the value rather than crashing (or stripping it).
Found by scan-build.
https://bugzilla.gnome.org/719533
len = strlen (value);
- if (value[0] == '\"') {
- if (value[len - 1] == '\"') {
- if (retval)
- g_free (retval);
-
- retval = g_strndup (
- value + 1, len - 2);
- }
- } else {
- if (retval)
- g_free (retval);
-
- retval = g_strdup (line + strlen (key_eq));
+ if (value[0] == '\"' && value[len - 1] == '\"') {
+ value += 1;
+ len -= 2;
}
+ g_free (retval);
+ retval = g_strndup (value, len);
g_strstrip (retval);
}