[Ocfs2-tools-devel] [PATCH V2] debugfs.ocfs2: Fix a bug in process_open_args()

piaojun piaojun at huawei.com
Tue May 5 19:25:10 PDT 2015


In process_open_args(), 'dev' get the wrong value because getopt() will
change the value of args[1]. This problem will cause failure in
debugfs.ocfs2. ocfs2. So we should assign 'dev' before getopt().

Signed-off-by: Jun Piao <piaojun at huawei.com>
Reviewed-by: Alex Chen <alex.chen at huawei.com>

---
 debugfs.ocfs2/commands.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/debugfs.ocfs2/commands.c b/debugfs.ocfs2/commands.c
index 1b0b2d9..6da396a 100644
--- a/debugfs.ocfs2/commands.c
+++ b/debugfs.ocfs2/commands.c
@@ -534,6 +534,7 @@ static int process_open_args(char **args,
 	int num, argc, c;

 	for (argc = 0; (args[argc]); ++argc);
+	dev = strdup(args[1]);
 	optind = 0;
 	while ((c = getopt(argc, args, "is:")) != EOF) {
 		switch (c) {
@@ -544,26 +545,31 @@ static int process_open_args(char **args,
 				s = strtoul(optarg, &ptr, 0);
 				break;
 			default:
-				return 1;
+				ret = 1;
+				goto bail;
 				break;
 		}
 	}

-	if (!s)
-		return 0;
+	if (!s) {
+		ret = 0;
+		goto bail;
+	}

 	num = ocfs2_get_backup_super_offsets(NULL, byte_off,
 					     ARRAY_SIZE(byte_off));
-	if (!num)
-		return -1;
+	if (!num) {
+		ret = -1;
+		goto bail;
+	}

 	if (s < 1 || s > num) {
 		fprintf(stderr, "Backup super block is outside of valid range"
 			"(between 1 and %d)\n", num);
-		return -1;
+		ret = -1;
+		goto bail;
 	}

-	dev = strdup(args[1]);
 	ret = get_blocksize(dev, byte_off[s-1], &blksize, s);
 	if (ret) {
 		com_err(args[0],ret, "Can't get the blocksize from the device"
-- 
1.8.4.3




More information about the Ocfs2-tools-devel mailing list