diff options
author | Corubba Smith <corubba@gmx.de> | 2025-03-08 23:36:33 +0100 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2025-03-12 09:10:06 +0100 |
commit | 752117f7eacd5558145c0921caacea2e8b57417d (patch) | |
tree | 944c3843a46ad55909b64428eec9d9a0fa10a5f8 | |
parent | 4c2a07b55d9e8a8366a1d3f5d04a2e6b971c0475 (diff) |
ulogd: ignore malformed config directives
When a config directive is provided with a malformed argument (e.g.
`loglevel="1`), then the call to get_word() returns NULL and `wordbuf`
is left unchanged aka still contains the directive name. Unlike the
previous calls to get_word(), the return value is not checked here, and
processing continues with `args` pointing to the still unchanged
`wordbuf`. So `loglevel="1` is effectively parsed as
`loglevel=loglevel`.
Instead if no valid argument is found, ignore the directive and log a
warning.
Due to the way get_word() is implemented, this unfortunately will report
an empty argument (e.g. `loglevel=`) as malformed as well. Ideally that
should behave the same as `loglevel=""`, but I found no nice way to
achieve that. An empty argument is only useful in rare cases, so
treating it as malformed should be fine for now. That's still way better
than the previous broken "name as value" behaviour.
Fixes: e88384d9d5a1 ("added new generic get_word() function to do better parsing")
Signed-off-by: Corubba Smith <corubba@gmx.de>
Signed-off-by: Florian Westphal <fw@strlen.de>
-rw-r--r-- | src/conffile.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/conffile.c b/src/conffile.c index 5b7f834..cc5552c 100644 --- a/src/conffile.c +++ b/src/conffile.c @@ -198,6 +198,12 @@ int config_parse_file(const char *section, struct config_keyset *kset) } wordend = get_word(wordend, " =\t\n\r", (char *) &wordbuf); + if (wordend == NULL) { + ulogd_log(ULOGD_NOTICE, + "ignoring malformed config directive \"%s\" on line %d\n", + ce->key, linenum); + break; + } args = (char *)&wordbuf; if (ce->hit && !(ce->options & CONFIG_OPT_MULTI)) |