From 19efaabf2b610205b1e93489e3084e3d62bc54b7 Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Tue, 5 Feb 2008 12:09:49 +0000 Subject: Fix crash with really small lines that are invalid, like just "a". Fox bug 2008-02-05 Vincent Untz Fix crash with really small lines that are invalid, like just "a". Fox bug #14386. * src/validate.c: (validate_line_looks_like_group): only return something in *group if the group argument is not NULL, and if the line is actually a group one (validate_parse_line): ensure we pass NULL initial values to some functions, and don't leak key and value when processing a key-value line before the first group --- ChangeLog | 12 ++++++++++++ src/validate.c | 11 ++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7e79b13..dcf3057 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-02-05 Vincent Untz + + Fix crash with really small lines that are invalid, like just "a". + Fox bug #14386. + + * src/validate.c: (validate_line_looks_like_group): only return + something in *group if the group argument is not NULL, and if the line + is actually a group one + (validate_parse_line): ensure we pass NULL initial values to some + functions, and don't leak key and value when processing a key-value + line before the first group + 2008-01-20 Vincent Untz * src/update-desktop-database.c: (process_desktop_file): don't get the diff --git a/src/validate.c b/src/validate.c index 702a78c..3474e0e 100644 --- a/src/validate.c +++ b/src/validate.c @@ -1911,7 +1911,8 @@ validate_line_looks_like_group (kf_validator *kf, "The validation will continue, with the trailing spaces " "ignored.\n", line); - *group = g_strndup (chomped + 1, strlen (chomped) - 2); + if (group && result) + *group = g_strndup (chomped + 1, strlen (chomped) - 2); g_free (chomped); @@ -1988,6 +1989,7 @@ validate_parse_line (kf_validator *kf) if (validate_line_is_comment (kf, line)) return; + group = NULL; if (validate_line_looks_like_group (kf, line, &group)) { if (!kf->current_group && (strcmp (group, GROUP_DESKTOP_ENTRY) && @@ -2012,6 +2014,8 @@ validate_parse_line (kf_validator *kf) return; } + key = NULL; + value = NULL; if (validate_line_looks_like_entry (kf, line, &key, &value)) { if (kf->current_group) { GSList *keys; @@ -2025,6 +2029,11 @@ validate_parse_line (kf_validator *kf) keys = g_slist_prepend (keys, keyvalue); g_hash_table_replace (kf->groups, g_strdup (kf->current_group), keys); } else { + if (key) + g_free (key); + if (value) + g_free (value); + print_fatal (kf, "file contains entry \"%s\" before the first group, " "but only comments are accepted before the first " "group\n", line); -- cgit v1.2.3