]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ext4: avoid stamping on other memories in ext4_ext_insert_index()
authorTao Ma <boyu.mt@taobao.com>
Sat, 8 Oct 2011 21:18:27 +0000 (17:18 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 8 Oct 2011 21:18:27 +0000 (17:18 -0400)
In ext4_ext_insert_index, we initialize 'ix' before checking its
validity, so we have a chance to stamp on memories out of the block.
Move the check before we do the work.

Signed-off-by: Tao Ma <boyu.mt@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
fs/ext4/extents.c

index f473ddf0bd949f477db42d7f7145c412b67dc815..2dff31efa33e5be61f47eb51b4757f879706f48e 100644 (file)
@@ -779,15 +779,15 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode,
                ix = curp->p_idx;
        }
 
-       ix->ei_block = cpu_to_le32(logical);
-       ext4_idx_store_pblock(ix, ptr);
-       le16_add_cpu(&curp->p_hdr->eh_entries, 1);
-
        if (unlikely(ix > EXT_LAST_INDEX(curp->p_hdr))) {
                EXT4_ERROR_INODE(inode, "ix > EXT_LAST_INDEX!");
                return -EIO;
        }
 
+       ix->ei_block = cpu_to_le32(logical);
+       ext4_idx_store_pblock(ix, ptr);
+       le16_add_cpu(&curp->p_hdr->eh_entries, 1);
+
        err = ext4_ext_dirty(handle, inode, curp);
        ext4_std_error(inode->i_sb, err);