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.
This commit is contained in:
Lennart Poettering
2026-04-27 20:12:46 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent b10d3631f3
commit bd2d2fec80
+3 -1
View 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;
}