libecal: Refactor system timezone key file parsing code
authorPhilip Withnall <philip.withnall@collabora.co.uk>
Fri, 29 Nov 2013 08:51:11 +0000 (08:51 +0000)
committerMatthew Barnes <mbarnes@redhat.com>
Tue, 3 Dec 2013 20:32:54 +0000 (15:32 -0500)
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

calendar/libecal/e-cal-system-timezone.c

index 8015428..78767ca 100644 (file)
@@ -140,21 +140,13 @@ system_timezone_read_key_file (const gchar *filename,
 
                        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);
                }