Fix byte-swapping issues for the i_extra_size field

Thanks to Andreas Dilger and Kalpak Shah for spotting this problem.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
Theodore Ts'o 2007-06-22 19:53:21 -04:00
parent a34c6ffd68
commit c844010cc4
2 changed files with 15 additions and 6 deletions

View File

@ -1,3 +1,8 @@
2007-06-22 Theodore Tso <tytso@mit.edu>
* swapfs.c (ext2fs_swap_inode_full): Fix byte-swapping issues for
i_extra_size field.
2007-06-12 Theodore Tso <tytso@mit.edu> 2007-06-12 Theodore Tso <tytso@mit.edu>
* openfs.c (ext2fs_open2): We now set EXT2_FLAG_MASTER_SB_ONLY * openfs.c (ext2fs_open2): We now set EXT2_FLAG_MASTER_SB_ONLY

View File

@ -133,7 +133,7 @@ void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
struct ext2_inode_large *f, int hostorder, struct ext2_inode_large *f, int hostorder,
int bufsize) int bufsize)
{ {
unsigned i, has_data_blocks; unsigned i, has_data_blocks, extra_isize;
int islnk = 0; int islnk = 0;
__u32 *eaf, *eat; __u32 *eaf, *eat;
@ -214,31 +214,35 @@ void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
if (bufsize < (int) (sizeof(struct ext2_inode) + sizeof(__u16))) if (bufsize < (int) (sizeof(struct ext2_inode) + sizeof(__u16)))
return; /* no i_extra_isize field */ return; /* no i_extra_isize field */
if (hostorder)
extra_isize = f->i_extra_isize;
t->i_extra_isize = ext2fs_swab16(f->i_extra_isize); t->i_extra_isize = ext2fs_swab16(f->i_extra_isize);
if (t->i_extra_isize > EXT2_INODE_SIZE(fs->super) - if (!hostorder)
extra_isize = t->i_extra_isize;
if (extra_isize > EXT2_INODE_SIZE(fs->super) -
sizeof(struct ext2_inode)) { sizeof(struct ext2_inode)) {
/* this is error case: i_extra_size is too large */ /* this is error case: i_extra_size is too large */
return; return;
} }
i = sizeof(struct ext2_inode) + t->i_extra_isize + sizeof(__u32); i = sizeof(struct ext2_inode) + extra_isize + sizeof(__u32);
if (bufsize < (int) i) if (bufsize < (int) i)
return; /* no space for EA magic */ return; /* no space for EA magic */
eaf = (__u32 *) (((char *) f) + sizeof(struct ext2_inode) + eaf = (__u32 *) (((char *) f) + sizeof(struct ext2_inode) +
f->i_extra_isize); extra_isize);
if (ext2fs_swab32(*eaf) != EXT2_EXT_ATTR_MAGIC) if (ext2fs_swab32(*eaf) != EXT2_EXT_ATTR_MAGIC)
return; /* it seems no magic here */ return; /* it seems no magic here */
eat = (__u32 *) (((char *) t) + sizeof(struct ext2_inode) + eat = (__u32 *) (((char *) t) + sizeof(struct ext2_inode) +
f->i_extra_isize); extra_isize);
*eat = ext2fs_swab32(*eaf); *eat = ext2fs_swab32(*eaf);
/* convert EA(s) */ /* convert EA(s) */
ext2fs_swap_ext_attr((char *) (eat + 1), (char *) (eaf + 1), ext2fs_swap_ext_attr((char *) (eat + 1), (char *) (eaf + 1),
bufsize - sizeof(struct ext2_inode) - bufsize - sizeof(struct ext2_inode) -
t->i_extra_isize - sizeof(__u32), 0); extra_isize - sizeof(__u32), 0);
} }