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 a85428b1d3
Follow-up for 059afcadfd

Signed-off-by: dongshengyuan <dongshengyuan@uniontech.com>
This commit is contained in:
dongshengyuan
2026-07-08 16:53:30 +08:00
committed by Luca Boccassi
parent 1b03303998
commit da9a330dfd

View File

@@ -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;
}
}