Fix possible segfault in get_keyfile_int() if key value is malformed.
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4247 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
c0dcc7002b
commit
e0bf328c15
@ -26,6 +26,8 @@
|
|||||||
Change new html_asp_default_language markup pref to use integer,
|
Change new html_asp_default_language markup pref to use integer,
|
||||||
not hex in config file.
|
not hex in config file.
|
||||||
Fix minor issue with changing pref back to 0.
|
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>
|
2009-09-24 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||||
|
|||||||
@ -350,15 +350,24 @@ static void get_keyfile_hex(GKeyFile *config, GKeyFile *configh,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Get first and second integer numbers, store in foreground and background fields of @a style.
|
static void convert_int(const gchar *int_str, gint *val)
|
||||||
* FIXME: is not safe for badly formed key e.g. "key=" */
|
{
|
||||||
|
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,
|
static void get_keyfile_int(GKeyFile *config, GKeyFile *configh, const gchar *section,
|
||||||
const gchar *key, gint fdefault_val, gint sdefault_val,
|
const gchar *key, gint fdefault_val, gint sdefault_val,
|
||||||
GeanyLexerStyle *style)
|
GeanyLexerStyle *style)
|
||||||
{
|
{
|
||||||
gchar **list;
|
gchar **list;
|
||||||
gchar *end1, *end2;
|
|
||||||
gsize len;
|
gsize len;
|
||||||
|
GeanyLexerStyle def = {fdefault_val, sdefault_val, FALSE, FALSE};
|
||||||
|
|
||||||
g_return_if_fail(config);
|
g_return_if_fail(config);
|
||||||
g_return_if_fail(configh);
|
g_return_if_fail(configh);
|
||||||
@ -369,21 +378,18 @@ static void get_keyfile_int(GKeyFile *config, GKeyFile *configh, const gchar *se
|
|||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
list = g_key_file_get_string_list(config, section, key, &len, NULL);
|
list = g_key_file_get_string_list(config, section, key, &len, NULL);
|
||||||
|
|
||||||
if (G_LIKELY(list != NULL) && G_LIKELY(list[0] != NULL))
|
*style = def;
|
||||||
style->foreground = strtol(list[0], &end1, 10);
|
if (!list)
|
||||||
else
|
return;
|
||||||
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;
|
|
||||||
|
|
||||||
/* 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);
|
g_strfreev(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user