]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
options: tighten validation of argc/argv
authorLennart Poettering <lennart@amutable.com>
Fri, 24 Apr 2026 08:37:48 +0000 (10:37 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Mon, 27 Apr 2026 18:12:46 +0000 (20:12 +0200)
If argc/argv do no match a lot of our assumptions are invalid, hence
let's check this explicitly once, instead of ignoring the issue.

src/shared/options.c

index 644c7ae27c3db049d0d4d55216de9cb17ff044b5..0c3188bf786814b3998be2f5d793b6fdffdaa34a 100644 (file)
@@ -76,9 +76,11 @@ int option_parse(
         if (state->optind == 0) {
                 assert(state->mode >= 0 && state->mode < _OPTION_PARSER_MODE_MAX);
 
-                if (state->argc < 1 || strv_isempty(state->argv))
+                if (state->argc < 1)
                         return log_error_errno(SYNTHETIC_ERRNO(EUCLEAN), "argv cannot be empty");
 
+                assert_se((size_t) state->argc == strv_length(state->argv)); /* Make sure argc/argv are consistent */
+
                 state->optind = state->positional_offset = 1;
         }