cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH] fsck.gfs2: Allocate enough space for the block map
Date: Mon, 19 Aug 2013 16:18:11 +0100	[thread overview]
Message-ID: <1376925491-26225-1-git-send-email-anprice@redhat.com> (raw)

Building with gcc 4.8's address sanitizer and running the test suite
throws up an issue where the block map allocated in fsck.gfs2 is not
large enough when the required size is an odd number. For example, when
the number of blocks is 3, the mapsize (number of chars to allocate
memory for) would be (3 >> 1) which is too small as each block requires
4 bits. This patch adds 1 to the mapsize, as suggested in an existing
comment, to ensure we have enough space in these situations.

Note that this has (probably) never made fsck.gfs2 misbehave as it only
ever accessed 4 bits past the end of the block map and by chance that
memory was never being modified by anything else in the rare cases in
which it was used.

Resolves: bz#947384

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/fsck/util.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index 408d89a..3e3050f 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -534,15 +534,10 @@ static int gfs2_blockmap_create(struct gfs2_bmap *bmap, uint64_t size)
 
 	/* Have to add 1 to BLOCKMAP_SIZE since it's 0-based and mallocs
 	 * must be 1-based */
-	bmap->mapsize = BLOCKMAP_SIZE4(size);
+	bmap->mapsize = BLOCKMAP_SIZE4(size) + 1;
 
-	if (!(bmap->map = malloc(sizeof(char) * bmap->mapsize)))
+	if (!(bmap->map = calloc(bmap->mapsize, sizeof(char))))
 		return -ENOMEM;
-	if (!memset(bmap->map, 0, sizeof(char) * bmap->mapsize)) {
-		free(bmap->map);
-		bmap->map = NULL;
-		return -ENOMEM;
-	}
 	return 0;
 }
 
-- 
1.8.3.1



                 reply	other threads:[~2013-08-19 15:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1376925491-26225-1-git-send-email-anprice@redhat.com \
    --to=anprice@redhat.com \
    /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).