Ilya Dryomov
2011-Nov-01 21:47 UTC
[PATCH] Btrfs-progs: fail gracefully on error from open_ctree()
Error checking block got moved mistakenly exposing us to a potential
segmentation fault.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
---
mkfs.c | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/mkfs.c b/mkfs.c
index e3ced19..a6f6b1f 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -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) {
--
1.7.6.3
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs"
in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2011-Dec-12 14:40 UTC
Re: [PATCH] Btrfs-progs: fail gracefully on error from open_ctree()
On Tue, Nov 01, 2011 at 11:47:22PM +0200, Ilya Dryomov wrote:> --- a/mkfs.c > +++ b/mkfs.c > @@ -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> + } > 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) {david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Ilya Dryomov
2011-Dec-12 18:07 UTC
Re: [PATCH] Btrfs-progs: fail gracefully on error from open_ctree()
On Mon, Dec 12, 2011 at 03:40:19PM +0100, David Sterba wrote:> On Tue, Nov 01, 2011 at 11:47:22PM +0200, Ilya Dryomov wrote: > > --- a/mkfs.c > > +++ b/mkfs.c > > @@ -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 doesI updated the patch. Thanks, Ilya -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html