linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Btrfs-progs: Check on num_stripes in print_chunk
@ 2017-08-24 10:38 zhangyu-fnst
  2017-09-06 17:51 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: zhangyu-fnst @ 2017-08-24 10:38 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Zhang Yu

From: Zhang Yu <zhangyu-fnst@cn.fujitsu.com>

[TEST/fuzz] case: 004-simple-dump-tree

Since the wrong key(DATA_RELOC_TREE CHUNK_ITEM 0) in root tree,
error calling print_chunk(), resulting in num_stripes == 0.

ERROR:
     [TEST/fuzz]   004-simple-dump-tree
ctree.h:317: btrfs_chunk_item_size: BUG_ON `num_stripes == 0`
        triggered, value 1

failed (ignored, ret=134): /myproject/btrfs-progs/btrfs
inspect-internal dump-tree
/myproject/btrfs-progs/tests/fuzz-tests/images/
bko-155201-wrong-chunk-item-in-root-tree.raw.restored

test failed for case 004-simple-dump-tree
Makefile:288: recipe for target 'test-fuzz' failed
make: *** [test-fuzz] Error 1

So, check on num_stripes in print_chunk

Signed-off-by: Zhang Yu <zhangyu-fnst@cn.fujitsu.com>
---
 print-tree.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/print-tree.c b/print-tree.c
index a0d3395..08f7edb 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -199,6 +199,15 @@ void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
 {
 	int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
 	int i;
+	/*
+	 * check on num_stripes
+	 * Btrfs_chunk contains at least one stripes
+	 */
+	if (num_stripes < 1) {
+		printf("invalid num_stripes: %u\n", num_stripes);
+		return;
+	}
+
 	u32 chunk_item_size = btrfs_chunk_item_size(num_stripes);
 	char chunk_flags_str[32] = {0};
 
-- 
2.9.4




^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-06 17:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-24 10:38 [PATCH] Btrfs-progs: Check on num_stripes in print_chunk zhangyu-fnst
2017-09-06 17:51 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).