Confparse: Fix possibly segfault if there is many option on a single line and if there is a missing '='.

This commit is contained in:
Martin Duquesnoy
2009-08-23 14:34:04 +02:00
parent 6715ba034b
commit 77ead81d3f
2 changed files with 21 additions and 9 deletions

View File

@@ -301,21 +301,20 @@ conf_layout_section(char *src)
{ {
tmp = get_nsec(src, "layout", i); tmp = get_nsec(src, "layout", i);
if(!name_to_func(get_opt(tmp, "", "type").str, layout_list)) if(!name_to_func(get_opt(tmp, "tile", "type").str, layout_list))
{ {
fprintf(stderr, "WMFS Configuration: Unknow Layout type: \"%s\"\n", fprintf(stderr, "WMFS Configuration: Unknow Layout type: \"%s\"\n",
get_opt(tmp, "", "type").str); get_opt(tmp, "tile", "type").str);
/* exit(EXIT_FAILURE); */
} }
else else
{ {
if(conf.layout_system && conf.nlayout > 1) if(conf.layout_system && conf.nlayout > 1)
menu_new_item(&menulayout.item[i], get_opt(tmp, "", "symbol").str, menu_new_item(&menulayout.item[i], get_opt(tmp, "", "symbol").str,
uicb_set_layout, uicb_set_layout,
get_opt(tmp, "", "type").str); get_opt(tmp, "tile", "type").str);
conf.layout[i].symbol = get_opt(tmp, "", "symbol").str; conf.layout[i].symbol = get_opt(tmp, "TILE (default)", "symbol").str;
conf.layout[i].func = name_to_func(get_opt(tmp, "", "type").str, layout_list); conf.layout[i].func = name_to_func(get_opt(tmp, "tile", "type").str, layout_list);
} }
} }
} }
@@ -507,8 +506,8 @@ conf_keybind_section(char *src)
fprintf(stderr, "WMFS Configuration warning: Unknow Function \"%s\"\n", get_opt(tmp, "", "func").str); fprintf(stderr, "WMFS Configuration warning: Unknow Function \"%s\"\n", get_opt(tmp, "", "func").str);
keys[i].func = uicb_spawn; keys[i].func = uicb_spawn;
} }
keys[i].cmd = (!get_opt(tmp, "", "cmd").str) ? NULL : get_opt(tmp, "", "cmd").str;
keys[i].cmd = (!get_opt(tmp, "", "cmd").str) ? NULL : get_opt(tmp, "", "cmd").str;
} }
return; return;

View File

@@ -152,7 +152,7 @@ opt_type
get_opt(char *src, char *def, char *name) get_opt(char *src, char *def, char *name)
{ {
int i; int i;
char *p = NULL; char *p = NULL, *p2 = NULL;
opt_type ret = null_opt_type; opt_type ret = null_opt_type;
if(!src || !name) if(!src || !name)
@@ -163,8 +163,21 @@ get_opt(char *src, char *def, char *name)
for(i = 0; p[i] && p[i] != '\n'; ++i); for(i = 0; p[i] && p[i] != '\n'; ++i);
p[i] = '\0'; p[i] = '\0';
p2 = _strdup(p + strlen(name));
if((p = strchr(p, '=')) && !is_in_delimiter(p, 0)) if((p = strchr(p, '=')) && !is_in_delimiter(p, 0))
{
for(i = 0; p2[i] && p2[i] != '='; ++i);
p2[i] = '\0';
/* Check if there is anything else that spaces
* between option name and '=' */
for(i = 0; i < strlen(p2); ++i)
if(p2[i] != ' ')
return str_to_opt(def);
ret = str_to_opt(clean_value(++p)); ret = str_to_opt(clean_value(++p));
}
} }
else else
ret = str_to_opt(def); ret = str_to_opt(def);
@@ -214,7 +227,7 @@ get_list_opt(char *src, char *def, char *name, int *n)
/* Set all value in return array */ /* Set all value in return array */
for(i = j = 0; i < *n; ++i, p2 += ++j) for(i = j = 0; i < *n; ++i, p2 += ++j)
{ {
for(j = 0; j < strlen(p2) && (p2[j] != ',' || is_in_delimiter(p2, j)); j++); for(j = 0; j < strlen(p2) && (p2[j] != ',' || is_in_delimiter(p2, j)); ++j);
p2[j] = '\0'; p2[j] = '\0';
ret[i] = str_to_opt(clean_value(p2)); ret[i] = str_to_opt(clean_value(p2));