From 77ead81d3f23e6ae8e69773f103b60f89b957678 Mon Sep 17 00:00:00 2001 From: Martin Duquesnoy Date: Sun, 23 Aug 2009 14:34:04 +0200 Subject: [PATCH] Confparse: Fix possibly segfault if there is many option on a single line and if there is a missing '='. --- src/config.c | 13 ++++++------- src/confparse/confparse.c | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/config.c b/src/config.c index ba3c773..d8fb1df 100644 --- a/src/config.c +++ b/src/config.c @@ -301,21 +301,20 @@ conf_layout_section(char *src) { 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", - get_opt(tmp, "", "type").str); - /* exit(EXIT_FAILURE); */ + get_opt(tmp, "tile", "type").str); } else { if(conf.layout_system && conf.nlayout > 1) menu_new_item(&menulayout.item[i], get_opt(tmp, "", "symbol").str, 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].func = name_to_func(get_opt(tmp, "", "type").str, layout_list); + conf.layout[i].symbol = get_opt(tmp, "TILE (default)", "symbol").str; + 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); 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; diff --git a/src/confparse/confparse.c b/src/confparse/confparse.c index 722b50a..ab83d1d 100644 --- a/src/confparse/confparse.c +++ b/src/confparse/confparse.c @@ -152,7 +152,7 @@ opt_type get_opt(char *src, char *def, char *name) { int i; - char *p = NULL; + char *p = NULL, *p2 = NULL; opt_type ret = null_opt_type; if(!src || !name) @@ -163,8 +163,21 @@ get_opt(char *src, char *def, char *name) for(i = 0; p[i] && p[i] != '\n'; ++i); p[i] = '\0'; + p2 = _strdup(p + strlen(name)); + 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)); + } } else 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 */ 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'; ret[i] = str_to_opt(clean_value(p2));