Ensure config variables match on longest-length (#2306)

fixes #2235
This commit is contained in:
Kyle Kneitinger
2016-04-26 00:20:42 -07:00
committed by Michael Stapelberg
parent 23beac46b7
commit 2123888d4d
2 changed files with 31 additions and 1 deletions

View File

@ -879,9 +879,23 @@ bool parse_file(const char *f, bool use_nagbar) {
v_value++;
struct Variable *new = scalloc(1, sizeof(struct Variable));
struct Variable *test = NULL, *loc = NULL;
new->key = sstrdup(v_key);
new->value = sstrdup(v_value);
SLIST_INSERT_HEAD(&variables, new, variables);
/* ensure that the correct variable is matched in case of one being
* the prefix of another */
SLIST_FOREACH(test, &variables, variables) {
if (strlen(new->key) >= strlen(test->key))
break;
loc = test;
}
if (loc == NULL) {
SLIST_INSERT_HEAD(&variables, new, variables);
} else {
SLIST_INSERT_AFTER(loc, new, variables);
}
DLOG("Got new variable %s = %s\n", v_key, v_value);
continue;
}