diff options
author | Matthias Clasen <mclasen@redhat.com> | 2006-03-14 17:56:27 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2006-03-14 17:56:27 +0000 |
commit | 9e5824666934f99d6f43acc9020970bd8279c679 (patch) | |
tree | a93e158ba22b0eb7e5e3795896475bab9ef29812 | |
parent | 99024c7ea7be03b02b8084a739153b93e21a6f44 (diff) |
Don't read past the end of the string. (#334471, Morten Welinder)
2006-03-14 Matthias Clasen <mclasen@redhat.com>
* glib/gutils.c (g_parse_debug_string): Don't read past the
end of the string. (#334471, Morten Welinder)
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | ChangeLog.pre-2-10 | 6 | ||||
-rw-r--r-- | ChangeLog.pre-2-12 | 6 | ||||
-rw-r--r-- | glib/gutils.c | 14 | ||||
-rw-r--r-- | tests/testglib.c | 29 |
5 files changed, 52 insertions, 9 deletions
@@ -1,5 +1,11 @@ 2006-03-14 Matthias Clasen <mclasen@redhat.com> + * glib/gutils.c (g_parse_debug_string): Don't read past the + end of the string. (#334471, Morten Welinder) + + * tests/testglib.c (test_g_parse_debug_string): Add testss + for g_parse_debug_string. + * glib/goption.c (parse_short_option): Don't create the option_name twice. (#334519, Chris Wilson) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index c97d3d51f..48a7e3d48 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,5 +1,11 @@ 2006-03-14 Matthias Clasen <mclasen@redhat.com> + * glib/gutils.c (g_parse_debug_string): Don't read past the + end of the string. (#334471, Morten Welinder) + + * tests/testglib.c (test_g_parse_debug_string): Add testss + for g_parse_debug_string. + * glib/goption.c (parse_short_option): Don't create the option_name twice. (#334519, Chris Wilson) diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index c97d3d51f..48a7e3d48 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,5 +1,11 @@ 2006-03-14 Matthias Clasen <mclasen@redhat.com> + * glib/gutils.c (g_parse_debug_string): Don't read past the + end of the string. (#334471, Morten Welinder) + + * tests/testglib.c (test_g_parse_debug_string): Add testss + for g_parse_debug_string. + * glib/goption.c (parse_short_option): Don't create the option_name twice. (#334519, Chris Wilson) diff --git a/glib/gutils.c b/glib/gutils.c index 83ab9b1a5..eba093e13 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -591,23 +591,21 @@ g_parse_debug_string (const gchar *string, { const gchar *p = string; const gchar *q; - gboolean done = FALSE; - while (*p && !done) + while (*p) { q = strchr (p, ':'); if (!q) - { - q = p + strlen(p); - done = TRUE; - } + q = p + strlen(p); - for (i=0; i<nkeys; i++) + for (i = 0; i < nkeys; i++) if (g_ascii_strncasecmp (keys[i].key, p, q - p) == 0 && keys[i].key[q - p] == '\0') result |= keys[i].value; - p = q + 1; + p = q; + if (*p == ':') + p++; } } diff --git a/tests/testglib.c b/tests/testglib.c index c9f31156b..42f4fce9a 100644 --- a/tests/testglib.c +++ b/tests/testglib.c @@ -432,6 +432,31 @@ test_g_mkdir_with_parents (void) return TRUE; } +static void +test_g_parse_debug_string (void) +{ + GDebugKey keys[3] = { + { "foo", 1 }, + { "bar", 2 }, + { "baz", 4 } + }; + guint n_keys = 3; + guint result; + + result = g_parse_debug_string ("bar:foo:blubb", keys, n_keys); + g_assert (result == 3); + + result = g_parse_debug_string (":baz::_E@~!_::", keys, n_keys); + g_assert (result == 4); + + result = g_parse_debug_string ("", keys, n_keys); + g_assert (result == 0); + + result = g_parse_debug_string (" : ", keys, n_keys); + g_assert (result == 0); +} + + int main (int argc, char *argv[]) @@ -1488,7 +1513,9 @@ main (int argc, close (fd); g_clear_error (&error); remove (name_used); - + + test_g_parse_debug_string (); + return 0; } |