From: dongshengyuan <545258830@qq.com> Date: Wed, 8 Jul 2026 08:53:30 +0000 (+0800) Subject: fsck: don't apply invalid mode or repair values X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=da9a330dfd41e91cbfa6a6def2abb3706e280aa4;p=thirdparty%2Fsystemd.git fsck: don't apply invalid mode or repair values fsck_mode_from_string() and fsck_repair_from_string() return -EINVAL on a bad value. Store the result in a local variable first, and only update the global state on success. Otherwise an invalid value is logged as ignored, but still leaves a negative enum value behind. In the fsck.repair case that makes fsck_repair_option_to_string() return NULL and truncates the fsck command line. Follow-up for a85428b1d325654dc7e1afbabf4b689bd31116f5 Follow-up for 059afcadfd89c6c302f20c9ac1a1c44592b716df Signed-off-by: dongshengyuan --- diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 405e9c34fdd..cc8bfea681b 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -108,18 +108,22 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (proc_cmdline_value_missing(key, value)) return 0; - arg_mode = fsck_mode_from_string(value); - if (arg_mode < 0) - log_warning_errno(arg_mode, "Invalid fsck.mode= parameter, ignoring: %s", value); + FSCKMode mode = fsck_mode_from_string(value); + if (mode < 0) + log_warning_errno(mode, "Invalid fsck.mode= parameter, ignoring: %s", value); + else + arg_mode = mode; } else if (streq(key, "fsck.repair")) { if (proc_cmdline_value_missing(key, value)) return 0; - arg_repair = fsck_repair_from_string(value); - if (arg_repair < 0) - log_warning_errno(arg_repair, "Invalid fsck.repair= parameter, ignoring: %s", value); + FSCKRepair repair = fsck_repair_from_string(value); + if (repair < 0) + log_warning_errno(repair, "Invalid fsck.repair= parameter, ignoring: %s", value); + else + arg_repair = repair; } else if (streq(key, "fastboot") && !value) @@ -139,9 +143,11 @@ static void parse_credentials(void) { if (r < 0) log_debug_errno(r, "Failed to read credential 'fsck.mode', ignoring: %m"); else { - arg_mode = fsck_mode_from_string(value); - if (arg_mode < 0) - log_warning_errno(arg_mode, "Invalid 'fsck.mode' credential, ignoring: %s", value); + FSCKMode mode = fsck_mode_from_string(value); + if (mode < 0) + log_warning_errno(mode, "Invalid 'fsck.mode' credential, ignoring: %s", value); + else + arg_mode = mode; } value = mfree(value); @@ -150,9 +156,11 @@ static void parse_credentials(void) { if (r < 0) log_debug_errno(r, "Failed to read credential 'fsck.repair', ignoring: %m"); else { - arg_repair = fsck_repair_from_string(value); - if (arg_repair < 0) - log_warning_errno(arg_repair, "Invalid 'fsck.repair' credential, ignoring: %s", value); + FSCKRepair repair = fsck_repair_from_string(value); + if (repair < 0) + log_warning_errno(repair, "Invalid 'fsck.repair' credential, ignoring: %s", value); + else + arg_repair = repair; } }