From 2787276ec59e1d52087d307bc30446d088ec65bc Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 8 Aug 2005 18:57:04 -0500 Subject: [PATCH] Fix fencepost error in resize2fs caught by valgrind There was a off-by-one fencepost error in the logic used to check if we avoid copying zero-filled blocks when moving an inode table down by a block or two. Thanks to valgrind for catching it. As far as I know this fencepost error wasn't causing any actual problems, but it was definitely a bug. Signed-off-by: "Theodore Ts'o" --- resize/ChangeLog | 9 +++++++++ resize/resize2fs.c | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/resize/ChangeLog b/resize/ChangeLog index 88dfd9c1..b88505e3 100644 --- a/resize/ChangeLog +++ b/resize/ChangeLog @@ -1,3 +1,12 @@ +2005-08-08 Theodore Ts'o + + * resize2fs.c (move_itables): Fix fencepost error caught by valgrind. + (adjust_superblock): Clear the newly allocated descriptor + blocks when we allocate them to avoid false positives from + valgrind (and so that the unusued descriptors at the tail + end of the newly allocated descriptor blocks are zero'ed + out, include of random garbage). + 2006-06-30 Theodore Ts'o * Release of E2fsprogs 1.38 diff --git a/resize/resize2fs.c b/resize/resize2fs.c index fd14c840..695bf7b6 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -281,6 +281,11 @@ retry: &fs->group_desc); if (retval) goto errout; + if (fs->desc_blocks > rfs->old_fs->desc_blocks) + memset((char *) fs->group_desc + + (rfs->old_fs->desc_blocks * fs->blocksize), 0, + (fs->desc_blocks - rfs->old_fs->desc_blocks) * + fs->blocksize); } /* @@ -1379,7 +1384,7 @@ static errcode_t move_itables(ext2_resize_t rfs) * things by not rewriting blocks that we know to be zero * already. */ - for (cp = rfs->itable_buf+size, n=0; n < size; n++, cp--) + for (cp = rfs->itable_buf+size-1, n=0; n < size; n++, cp--) if (*cp) break; n = n >> EXT2_BLOCK_SIZE_BITS(fs->super);