From e1949aa69421ff6e8a540eb505ac5d00dee403a0 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 20 Sep 2011 21:42:09 +0100 Subject: [PATCH 1/2] Bugfix: Correctly split key/value when parsing variables (Thanks xeen) --- src/cfgparse.y | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cfgparse.y b/src/cfgparse.y index 10ca48cc..f8e84ae9 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -358,12 +358,14 @@ void parse_file(const char *f) { /* get key/value for this variable */ char *v_key = value, *v_value; - if ((v_value = strstr(value, " ")) == NULL && - (v_value = strstr(value, "\t")) == NULL) { + if (strstr(value, " ") == NULL && strstr(value, "\t") == NULL) { ELOG("Malformed variable assignment, need a value\n"); continue; } + if (!(v_value = strstr(value, " "))) + v_value = strstr(value, "\t"); + *(v_value++) = '\0'; struct Variable *new = scalloc(sizeof(struct Variable)); From cd6c3fedcb89b8ae995ca1afac2789aef5567de8 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 20 Sep 2011 21:42:26 +0100 Subject: [PATCH 2/2] A bit more boundary-checking when replacing variables. Makes valgrind happy --- src/cfgparse.y | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cfgparse.y b/src/cfgparse.y index f8e84ae9..f1843312 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -390,6 +390,7 @@ void parse_file(const char *f) { int extra = (strlen(current->value) - strlen(current->key)); char *next; for (next = bufcopy; + (bufcopy + (next - bufcopy)) < (buf + stbuf.st_size) && (next = strcasestr(bufcopy + (next - bufcopy), current->key)) != NULL; next += strlen(current->key)) { *next = '_';