From 07bb42ca797d78333b0fd47189a6504cd25b28d5 Mon Sep 17 00:00:00 2001 From: Gui Hecheng Date: Thu, 24 Apr 2014 11:39:28 +0800 Subject: [PATCH 16/42] btrfs-progs: prevent close_root if the root to close is potentially NULL Originally only if 'block_only' is specified, the 'fs_root == NULL' will be checked. But if 'block_only' is not specified and close_root will be called blindly without checking 'fs_root == NULL', which is unsafe. Signed-off-by: Gui Hecheng Signed-off-by: David Sterba --- btrfs-debug-tree.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c index 8ae7270dc2fe..cb6c1061b329 100644 --- a/btrfs-debug-tree.c +++ b/btrfs-debug-tree.c @@ -177,13 +177,14 @@ int main(int ac, char **av) fprintf(stderr, "unable to open %s\n", av[optind]); exit(1); } + root = info->fs_root; + if (!root) { + fprintf(stderr, "unable to open %s\n", av[optind]); + exit(1); + } if (block_only) { - if (!root) { - fprintf(stderr, "unable to open %s\n", av[optind]); - exit(1); - } leaf = read_tree_block(root, block_only, root->leafsize, 0); -- 1.9.0