From 4fd30c0330ba951d579ee3f0c24eaf1fa0580719 Mon Sep 17 00:00:00 2001 From: Tao Ma Date: Sat, 8 Oct 2011 17:18:27 -0400 Subject: [PATCH] ext4: avoid stamping on other memories in ext4_ext_insert_index() 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 Signed-off-by: "Theodore Ts'o" --- fs/ext4/extents.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index f473ddf0bd94..2dff31efa33e 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -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); -- 2.39.5