Revision: 4247 http://geany.svn.sourceforge.net/geany/?rev=4247&view=rev Author: ntrel Date: 2009-09-27 16:38:37 +0000 (Sun, 27 Sep 2009)
Log Message: ----------- Fix possible segfault in get_keyfile_int() if key value is malformed.
Modified Paths: -------------- trunk/ChangeLog trunk/src/highlighting.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-09-27 16:16:18 UTC (rev 4246) +++ trunk/ChangeLog 2009-09-27 16:38:37 UTC (rev 4247) @@ -26,6 +26,8 @@ Change new html_asp_default_language markup pref to use integer, not hex in config file. Fix minor issue with changing pref back to 0. + * src/highlighting.c: + Fix possible segfault in get_keyfile_int() if key value is malformed.
2009-09-24 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/src/highlighting.c =================================================================== --- trunk/src/highlighting.c 2009-09-27 16:16:18 UTC (rev 4246) +++ trunk/src/highlighting.c 2009-09-27 16:38:37 UTC (rev 4247) @@ -350,15 +350,24 @@ }
-/* Get first and second integer numbers, store in foreground and background fields of @a style. - * FIXME: is not safe for badly formed key e.g. "key=" */ +static void convert_int(const gchar *int_str, gint *val) +{ + gchar *end; + gint v = strtol(int_str, &end, 10); + + if (int_str != end) + *val = v; +} + + +/* Get first and second integer numbers, store in foreground and background fields of @a style. */ static void get_keyfile_int(GKeyFile *config, GKeyFile *configh, const gchar *section, const gchar *key, gint fdefault_val, gint sdefault_val, GeanyLexerStyle *style) { gchar **list; - gchar *end1, *end2; gsize len; + GeanyLexerStyle def = {fdefault_val, sdefault_val, FALSE, FALSE};
g_return_if_fail(config); g_return_if_fail(configh); @@ -369,21 +378,18 @@ if (list == NULL) list = g_key_file_get_string_list(config, section, key, &len, NULL);
- if (G_LIKELY(list != NULL) && G_LIKELY(list[0] != NULL)) - style->foreground = strtol(list[0], &end1, 10); - else - style->foreground = fdefault_val; - if (G_LIKELY(list != NULL) && G_LIKELY(list[1] != NULL)) - style->background = strtol(list[1], &end2, 10); - else - style->background = sdefault_val; + *style = def; + if (!list) + return;
- /* if there was an error, strtol() returns 0 and end is list[x], so then we use default_val */ - if (G_UNLIKELY(list == NULL) || G_UNLIKELY(list[0] == end1)) - style->foreground = fdefault_val; - if (G_UNLIKELY(list == NULL) || G_UNLIKELY(list[1] == end2)) - style->background = sdefault_val; - + if (list[0]) + { + convert_int(list[0], &style->foreground); + if (list[1]) + { + convert_int(list[1], &style->background); + } + } g_strfreev(list); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.