Skip to contentSkip to conversation

Btrfs-progs: fail gracefully on error from open_ctree()

PATCH In review Ilya Dryomov 2 participants 3 messages Nov 1, 2011 – Dec 12, 2011 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs-progs: fail gracefully on error from open_ctree()

Error checking block got moved mistakenly exposing us to a potential segmentation fault.

---
 mkfs.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
mkfs.c +5 -4
index e3ced19..a6f6b1f 100644
@@ -1328,7 +1328,12 @@ int main(int ac, char **av)
 		fprintf(stderr, "error during mkfs %d\n", ret);
 		exit(1);
 	}
+
 	root = open_ctree(file, 0, O_RDWR);
+	if (!root) {
+		fprintf(stderr, "ctree init failed\n");
+		return -1;
+	}
 	root->fs_info->alloc_start = alloc_start;
 
 	ret = make_root_dir(root, mixed);
@@ -1343,10 +1348,6 @@ int main(int ac, char **av)
 		goto raid_groups;
 
 	btrfs_register_one_device(file);
-	if (!root) {
-		fprintf(stderr, "ctree init failed\n");
-		return -1;
-	}
 
 	zero_end = 1;
 	while(ac-- > 0) {
Signature · 1 line
1.7.6.3
#1 lore raw

mkfs.c int main(int ac, char **av) · line 1335

Quoted 11 lines · Ilya Dryomov
mkfs.c +4 -0
@@ -1328,7 +1328,12 @@ int main(int ac, char **av)
 		fprintf(stderr, "error during mkfs %d\n", ret);
 		exit(1);
 	}
+
 	root = open_ctree(file, 0, O_RDWR);
+	if (!root) {
+		fprintf(stderr, "ctree init failed\n");
+		return -1;

I know you just moved the code, but this should be exit(1), same as the rest of the function does

Quoted 5 lines
mkfs.c +1 -0
+	}
 	root->fs_info->alloc_start = alloc_start;
 
 	ret = make_root_dir(root, mixed);

mkfs.c int main(int ac, char **av) · line 1353

Quoted 10 lines
mkfs.c +0 -4
@@ -1343,10 +1348,6 @@ int main(int ac, char **av)
 		goto raid_groups;
 
 	btrfs_register_one_device(file);
-	if (!root) {
-		fprintf(stderr, "ctree init failed\n");
-		return -1;
-	}
 
 	zero_end = 1;
 	while(ac-- > 0) {

david

#2 lore raw
Quoted 15 lines · David Sterba

mkfs.c int main(int ac, char **av) · line 1335

Quoted 11 lines · Ilya Dryomov
mkfs.c +4 -0
@@ -1328,7 +1328,12 @@ int main(int ac, char **av)
 		fprintf(stderr, "error during mkfs %d\n", ret);
 		exit(1);
 	}
+
 	root = open_ctree(file, 0, O_RDWR);
+	if (!root) {
+		fprintf(stderr, "ctree init failed\n");
+		return -1;

I know you just moved the code, but this should be exit(1), same as the rest of the function does

I updated the patch.

Thanks,

Ilya