linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zach Brown <zab@redhat.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 05/15] btrfs-progs: remove variable length stack arrays
Date: Wed, 14 Aug 2013 16:16:35 -0700	[thread overview]
Message-ID: <1376522205-16992-6-git-send-email-zab@redhat.com> (raw)
In-Reply-To: <1376522205-16992-1-git-send-email-zab@redhat.com>

sparse hates variable length array definitions on the stack:

 btrfs-show-super.c:155:21: warning: Variable length array is used.

And it's right to.  They're a fragile construct that doesn't handle bad
input well at all.

Signed-off-by: Zach Brown <zab@redhat.com>
---
 btrfs-show-super.c |  2 +-
 volumes.c          | 16 ++++++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/btrfs-show-super.c b/btrfs-show-super.c
index c2e844d..0c3c73c 100644
--- a/btrfs-show-super.c
+++ b/btrfs-show-super.c
@@ -152,7 +152,7 @@ static int load_and_dump_sb(char *filename, int fd, u64 sb_bytenr)
 
 static int check_csum_sblock(void *sb, int csum_size)
 {
-	char result[csum_size];
+	char result[BTRFS_CSUM_SIZE];
 	u32 crc = ~(u32)0;
 
 	crc = btrfs_csum_data(NULL, (char *)sb + BTRFS_CSUM_SIZE,
diff --git a/volumes.c b/volumes.c
index e460bce..dba5b0e 100644
--- a/volumes.c
+++ b/volumes.c
@@ -1779,12 +1779,15 @@ int write_raid56_with_parity(struct btrfs_fs_info *info,
 			     struct btrfs_multi_bio *multi,
 			     u64 stripe_len, u64 *raid_map)
 {
-	struct extent_buffer *ebs[multi->num_stripes], *p_eb = NULL, *q_eb = NULL;
+	struct extent_buffer **ebs, *p_eb = NULL, *q_eb = NULL;
 	int i;
 	int j;
 	int ret;
 	int alloc_size = eb->len;
 
+	ebs = kmalloc(sizeof(*ebs) * multi->num_stripes, GFP_NOFS);
+	BUG_ON(!ebs);
+
 	if (stripe_len > alloc_size)
 		alloc_size = stripe_len;
 
@@ -1813,7 +1816,12 @@ int write_raid56_with_parity(struct btrfs_fs_info *info,
 			q_eb = new_eb;
 	}
 	if (q_eb) {
-		void *pointers[multi->num_stripes];
+		void **pointers;
+
+		pointers = kmalloc(sizeof(*pointers) * multi->num_stripes,
+				   GFP_NOFS);
+		BUG_ON(!pointers);
+
 		ebs[multi->num_stripes - 2] = p_eb;
 		ebs[multi->num_stripes - 1] = q_eb;
 
@@ -1821,6 +1829,7 @@ int write_raid56_with_parity(struct btrfs_fs_info *info,
 			pointers[i] = ebs[i]->data;
 
 		raid6_gen_syndrome(multi->num_stripes, stripe_len, pointers);
+		kfree(pointers);
 	} else {
 		ebs[multi->num_stripes - 1] = p_eb;
 		memcpy(p_eb->data, ebs[0]->data, stripe_len);
@@ -1838,5 +1847,8 @@ int write_raid56_with_parity(struct btrfs_fs_info *info,
 		if (ebs[i] != eb)
 			kfree(ebs[i]);
 	}
+
+	kfree(ebs);
+
 	return 0;
 }
-- 
1.7.11.7


  parent reply	other threads:[~2013-08-14 23:17 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-14 23:16 [RFC] btrfs-progs: fix sparse checking and warnings Zach Brown
2013-08-14 23:16 ` [PATCH 01/15] btrfs-progs: get C=1 sparse checking working again Zach Brown
2013-08-30 16:08   ` David Sterba
2013-08-30 21:03     ` Zach Brown
2013-08-30 21:27       ` David Sterba
2013-08-14 23:16 ` [PATCH 02/15] btrfs-progs: remove __CHECKER__ from main code Zach Brown
2013-08-14 23:16 ` [PATCH 03/15] btrfs-progs: add ULL to u64 constant Zach Brown
2013-08-14 23:16 ` [PATCH 04/15] btrfs-progs: fix shadow symbols Zach Brown
2013-08-14 23:16 ` Zach Brown [this message]
2013-08-14 23:16 ` [PATCH 06/15] btrfs-print: define void function args Zach Brown
2013-08-14 23:16 ` [PATCH 07/15] btrfs-progs: fix endian bugs in chunk rebuilding Zach Brown
2013-08-30 16:16   ` David Sterba
2013-08-14 23:16 ` [PATCH 08/15] btrfs-progs: fix extent key endian bug in repair Zach Brown
2013-08-14 23:16 ` [PATCH 09/15] btrfs-progs: fix in-place byte swapping Zach Brown
2013-08-14 23:16 ` [PATCH 10/15] btrfs-progs: fix qgroup realloc inheritance Zach Brown
2013-08-18  8:05   ` Arne Jansen
2013-08-14 23:16 ` [PATCH 11/15] btrfs-progs: make many private symbols static Zach Brown
2013-08-14 23:16 ` [PATCH 12/15] btrfs-progs: fix unaligned compat endian warnings Zach Brown
2013-08-14 23:16 ` [PATCH 13/15] btrfs-progs: don't use <linux/fs.h> Zach Brown
2013-08-14 23:16 ` [PATCH 14/15] btrfs-progs: give raid6.c its exported prototypes Zach Brown
2013-08-14 23:16 ` [PATCH 15/15] btrfs-progs: use NULL instead of 0 Zach Brown
2013-08-30 16:25   ` David Sterba
2013-08-30 21:04     ` Zach Brown
2013-08-30 16:31 ` [RFC] btrfs-progs: fix sparse checking and warnings 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=1376522205-16992-6-git-send-email-zab@redhat.com \
    --to=zab@redhat.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).