diff options
author | Jan Kara <jack@suse.cz> | 2013-06-08 11:26:14 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2013-06-08 17:03:05 -0400 |
commit | 70f4632b626e3db94dd02c9dc9b4e643ffb0d048 (patch) | |
tree | 6f7ad3c02d23f684771c8144e393670543c53533 /lib/ext2fs/dir_iterate.c | |
parent | bd78b1dae99b0f0d3c5456478c320f5ac0a98584 (diff) | |
download | e2fsprogs-70f4632b626e3db94dd02c9dc9b4e643ffb0d048.tar.gz |
libext2fs: provide functions to safely access name_len and file_type
Accessing name_len (and file_type) in ext4_dir_entry structure is
somewhat problematic because on big endian architecture we need to now
whether we are really dealing with ext4_dir_entry (which has u16
name_len which needs byte swapping) or ext4_dir_entry_2 (which has u8
name_len which must not be byte swapped).
Currently the code is somewhat surprising and name_len is always
treated as u16 and byte swapped (flag EXT2_DIRBLOCK_V2_STRUCT isn't
ever used) and then masking of name_len is used to access real
name_len or file_type. Doing things this way in applications using
libext2fs is unexpected to say the least (more natural is to type
struct ext4_dir_entry * to struct ext4_dir_entry_2 * but that gives
wrong results on big endian architectures. So provide helper functions
that give endian-safe access to these fields. Also convert users in
e2fsprogs to use these functions.
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'lib/ext2fs/dir_iterate.c')
-rw-r--r-- | lib/ext2fs/dir_iterate.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/ext2fs/dir_iterate.c b/lib/ext2fs/dir_iterate.c index 1a4bf5cf..8be0ac23 100644 --- a/lib/ext2fs/dir_iterate.c +++ b/lib/ext2fs/dir_iterate.c @@ -83,7 +83,7 @@ static int ext2fs_validate_entry(ext2_filsys fs, char *buf, offset += rec_len; if ((rec_len < 8) || ((rec_len % 4) != 0) || - ((((unsigned) dirent->name_len & 0xFF)+8) > rec_len)) + ((ext2fs_dirent_name_len(dirent)+8) > rec_len)) return 0; } return (offset == final_offset); @@ -215,7 +215,7 @@ int ext2fs_process_dir_block(ext2_filsys fs, if (((offset + rec_len) > fs->blocksize) || (rec_len < 8) || ((rec_len % 4) != 0) || - ((((unsigned) dirent->name_len & 0xFF)+8) > rec_len)) { + ((ext2fs_dirent_name_len(dirent)+8) > rec_len)) { ctx->errcode = EXT2_ET_DIR_CORRUPTED; return BLOCK_ABORT; } @@ -253,7 +253,7 @@ next: next_real_entry += rec_len; if (ctx->flags & DIRENT_FLAG_INCLUDE_REMOVED) { - size = ((dirent->name_len & 0xFF) + 11) & ~3; + size = (ext2fs_dirent_name_len(dirent) + 11) & ~3; if (rec_len != size) { unsigned int final_offset; |