diff mbox

btrfs-progs: prevent close_root if the root to close is potentially NULL

Message ID 1398310768-32438-1-git-send-email-guihc.fnst@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Gui Hecheng April 24, 2014, 3:39 a.m. UTC
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 <guihc.fnst@cn.fujitsu.com>
---
 btrfs-debug-tree.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/btrfs-debug-tree.c b/btrfs-debug-tree.c
index 8ae7270..cb6c106 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);