btrfs-progs: tests: Fix fuzz-test for bko-161821.raw.txt
authorLu Fengqi <lufq.fnst@cn.fujitsu.com>
Tue, 2 May 2017 07:36:09 +0000 (15:36 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 2 May 2017 14:29:38 +0000 (16:29 +0200)
commit528ba342acfcce93457708ee5bdec98dee52645a
tree507344a62723606e2398099a83731494227b8ad8
parentf80b1f1db66216aeca06be03d0269b2e2946974b
btrfs-progs: tests: Fix fuzz-test for bko-161821.raw.txt

Fuzzed image bko-161821.raw causes btrfs check to get segmentation fault.

The function check_owner_ref attempts to access a non-exist quota tree
when dealing with extent_item [4198400 4096] in the corrupted filesystem.

The function btrfs_new_fs_info always allocates memory for
fs_info->quota_root regardless of whether quota_tree exists or not.
Additionally, the function btrfs_read_fs_root will directly return
fs_info->quota_root if location->objectid == BTRFS_QUOTA_TREE_OBJECTID.

This patch does the following things:
1. Do extra check and return ENOENT if quota tree does not exist in the
   function btrfs_read_fs_root.
2. Free useless fs_info->quota_root in the function btrfs_setup_all_roots
   to reduce confusion.
3. free_extent_buffer even if check_child_node failed in the function
   walk_down_tree.

Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-check.c
disk-io.c