OSDN Git Service

ext2fs_zero_blocks: Avoid clearing more blocks than requested
authorTheodore Ts'o <tytso@mit.edu>
Tue, 17 Jun 2008 04:18:58 +0000 (00:18 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 17 Jun 2008 05:14:30 +0000 (01:14 -0400)
This could cause certain mke2fs feature combinations to result in the
initial blocks of the inode table getting wiped out when the journal
is created.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/mkjournal.c

index ca8e733..e55dcbd 100644 (file)
@@ -170,9 +170,11 @@ errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num,
        /* OK, do the write loop */
        j=0;
        while (j < num) {
-               if (blk % STRIDE_LENGTH)
+               if (blk % STRIDE_LENGTH) {
                        count = STRIDE_LENGTH - (blk % STRIDE_LENGTH);
-               else {
+                       if (count > (num - j))
+                               count = num - j;
+               } else {
                        count = num - j;
                        if (count > STRIDE_LENGTH)
                                count = STRIDE_LENGTH;