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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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 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);
-- 
1.8.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux