[PATCH] erofs-utils: fsck: fix issues related to --extract=X

Igor Ostapenko igoreisberg at gmail.com
Fri Jan 28 15:46:13 AEDT 2022


From: Igor Eisberg <igoreisberg at gmail.com>

* Moved no_preserve_owner/no_preserve_perms to local scope.
* Added missing return -EINVAL.

Signed-off-by: Igor Ostapenko <igoreisberg at gmail.com>
---
 fsck/main.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/fsck/main.c b/fsck/main.c
index 9080a66..2f13870 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -31,8 +31,6 @@ struct erofsfsck_cfg {
 	bool overwrite;
 	bool preserve_owner;
 	bool preserve_perms;
-	bool no_preserve_owner;
-	bool no_preserve_perms;
 };
 static struct erofsfsck_cfg fsckcfg;
 
@@ -97,6 +95,7 @@ static void erofsfsck_print_version(void)
 static int erofsfsck_parse_options_cfg(int argc, char **argv)
 {
 	int opt, ret;
+	bool no_preserve_owner = false, no_preserve_perms = false;
 
 	while ((opt = getopt_long(argc, argv, "Vd:p",
 				  long_options, NULL)) != -1) {
@@ -154,32 +153,28 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 			fsckcfg.overwrite = true;
 			break;
 		case 6:
-			fsckcfg.preserve_owner = true;
-			fsckcfg.preserve_perms = true;
-			fsckcfg.no_preserve_owner = false;
-			fsckcfg.no_preserve_perms = false;
+			fsckcfg.preserve_owner = fsckcfg.preserve_perms = true;
+			no_preserve_owner = no_preserve_perms = false;
 			break;
 		case 7:
 			fsckcfg.preserve_owner = true;
-			fsckcfg.no_preserve_owner = false;
+			no_preserve_owner = false;
 			break;
 		case 8:
 			fsckcfg.preserve_perms = true;
-			fsckcfg.no_preserve_perms = false;
+			no_preserve_perms = false;
 			break;
 		case 9:
-			fsckcfg.no_preserve_owner = true;
-			fsckcfg.no_preserve_perms = true;
-			fsckcfg.preserve_owner = false;
-			fsckcfg.preserve_perms = false;
+			fsckcfg.preserve_owner = fsckcfg.preserve_perms = false;
+			no_preserve_owner = no_preserve_perms = true;
 			break;
 		case 10:
-			fsckcfg.no_preserve_owner = true;
 			fsckcfg.preserve_owner = false;
+			no_preserve_owner = true;
 			break;
 		case 11:
-			fsckcfg.no_preserve_perms = true;
 			fsckcfg.preserve_perms = false;
+			no_preserve_perms = true;
 			break;
 		default:
 			return -EINVAL;
@@ -192,13 +187,19 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 			return -EINVAL;
 		}
 	} else {
-		if (fsckcfg.force)
+		if (fsckcfg.force) {
 			erofs_err("--force must be used together with --extract=X");
-		if (fsckcfg.overwrite)
+			return -EINVAL;
+		}
+		if (fsckcfg.overwrite) {
 			erofs_err("--overwrite must be used together with --extract=X");
+			return -EINVAL;
+		}
 		if (fsckcfg.preserve_owner || fsckcfg.preserve_perms ||
-			  fsckcfg.no_preserve_owner || fsckcfg.no_preserve_perms)
+			  fsckcfg.no_preserve_owner || fsckcfg.no_preserve_perms) {
 			erofs_err("--[no-]preserve[-owner/-perms] must be used together with --extract=X");
+			return -EINVAL;
+		}
 	}
 
 	if (optind >= argc)
-- 
2.30.2



More information about the Linux-erofs mailing list