From: Lennart Poettering Date: Fri, 24 Apr 2026 08:37:48 +0000 (+0200) Subject: options: tighten validation of argc/argv X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=bd2d2fec80f059eff279c76275f564323259ca37;p=thirdparty%2Fsystemd.git options: tighten validation of argc/argv 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. --- diff --git a/src/shared/options.c b/src/shared/options.c index 644c7ae27c3..0c3188bf786 100644 --- a/src/shared/options.c +++ b/src/shared/options.c @@ -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; }