aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Ruppert <idl0r@gentoo.org>2011-07-09 23:05:11 +0200
committerChristian Ruppert <idl0r@gentoo.org>2011-07-09 23:15:16 +0200
commitef22868f3668fe833cdf297e619afe5b721f7716 (patch)
treec560faaa3a6d6377678b1408ae5ca0df2b3c47e0
parent0c7032840b746bc5f1e5f6cb90ad50b5da0a4fce (diff)
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.
-rw-r--r--src/librc/librc-misc.c12
1 files changed, 4 insertions, 8 deletions
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;
}
}