From ef22868f3668fe833cdf297e619afe5b721f7716 Mon Sep 17 00:00:00 2001 From: Christian Ruppert Date: Sat, 9 Jul 2011 23:05:11 +0200 Subject: Do not skip similar config options OpenRC goes through the config and checks each option for duplicates. Lets say we're on "rc_logger" currently and its the last option in the config file and we previously defined rc_logger_path. It now goes through all previous config options and compares those against the current one "rc_logger" *but* it compares only the first N bytes, in this case strlen("rc_logger"). So it strips the _path from "rc_logger_path" which ends up into "rc_logger" and it compares that against the current one (also "rc_logger"), it would then simply override the previous definition. This patch fixes this behaviour to always compare the full option / variable names. --- src/librc/librc-misc.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c index 15105c5d..7244deef 100644 --- a/src/librc/librc-misc.c +++ b/src/librc/librc-misc.c @@ -173,10 +173,8 @@ rc_config_load(const char *file) /* In shells the last item takes precedence, so we need to remove any prior values we may already have */ TAILQ_FOREACH(cline, config, entries) { - p = strchr(cline->value, '='); - if (p && strncmp(entry, cline->value, - (size_t)(p - cline->value)) == 0) - { + i = strlen(entry); + if (strncmp(entry, cline->value, i) == 0 && cline->value[i] == '=') { /* We have a match now - to save time we directly replace it */ free(cline->value); cline->value = newline; @@ -202,15 +200,13 @@ rc_config_value(RC_STRINGLIST *list, const char *entry) { RC_STRING *line; char *p; - size_t len, dif; + size_t len; len = strlen(entry); TAILQ_FOREACH(line, list, entries) { p = strchr(line->value, '='); if (p != NULL) { - dif = (p - line->value); - if (dif == len && - strncmp(entry, line->value, dif) == 0) + if (strncmp(entry, line->value, len) == 0 && line->value[len] == '=') return ++p; } } -- cgit v1.2.3