]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fsck: don't apply invalid mode or repair values
authordongshengyuan <545258830@qq.com>
Wed, 8 Jul 2026 08:53:30 +0000 (16:53 +0800)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 8 Jul 2026 11:13:43 +0000 (12:13 +0100)
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 <dongshengyuan@uniontech.com>
src/fsck/fsck.c

index 405e9c34fddc4fc19cbdda6573f4e0270a5f9b04..cc8bfea681bf7e695d4b5fe387ca7825684fd374 100644 (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;
         }
 }