]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
ulogd: ignore malformed config directives
authorCorubba Smith <corubba@gmx.de>
Sat, 8 Mar 2025 22:36:33 +0000 (23:36 +0100)
committerFlorian Westphal <fw@strlen.de>
Wed, 12 Mar 2025 08:10:06 +0000 (09:10 +0100)
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>
src/conffile.c

index 5b7f8341f111acfbd837437bc5af5eabb336f4c6..cc5552c4731605d11ec429af9d0993ee1467a936 100644 (file)
@@ -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))