linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <zhangyu-fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Zhang Yu <zhangyu-fnst@cn.fujitsu.com>
Subject: [PATCH] Btrfs-progs: Check on num_stripes in print_chunk
Date: Thu, 24 Aug 2017 18:38:41 +0800	[thread overview]
Message-ID: <20170824103841.16259-1-zhangyu-fnst@cn.fujitsu.com> (raw)

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




             reply	other threads:[~2017-08-24 10:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-24 10:38 zhangyu-fnst [this message]
2017-09-06 17:51 ` [PATCH] Btrfs-progs: Check on num_stripes in print_chunk David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170824103841.16259-1-zhangyu-fnst@cn.fujitsu.com \
    --to=zhangyu-fnst@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).