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" <tytso@mit.edu>
diff --git a/resize/ChangeLog b/resize/ChangeLog
index 88dfd9c..b88505e 100644
--- a/resize/ChangeLog
+++ b/resize/ChangeLog
@@ -1,3 +1,12 @@
+2005-08-08 Theodore Ts'o <tytso@mit.edu>
+
+ * 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 <tytso@mit.edu>
* Release of E2fsprogs 1.38
diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index fd14c84..695bf7b 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -281,6 +281,11 @@
&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 @@
* 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);