]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2fsck: fix endianness problem when reading htree nodes
authorLukas Czerner <lczerner@redhat.com>
Fri, 9 Mar 2018 11:28:02 +0000 (12:28 +0100)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 11 Mar 2018 02:23:16 +0000 (21:23 -0500)
Wrong directory block number can be saved in ->previous on big endian
system in parse_int_node(). Fix it by moving the mask out of the endian
conversion.

Fixes: ae9efd05a986 ("e2fsck: 3 level hash tree directory optimization")
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/pass2.c
lib/ext2fs/ext2_fs.h

index 1b0504c857a4795e9d264cd0c6ef6492fc8c8fdf..e922876d32ffd565f7ebb2a95760380c3d382341 100644 (file)
@@ -643,7 +643,7 @@ static void parse_int_node(ext2_filsys fs,
                printf("Entry #%d: Hash 0x%08x, block %u\n", i,
                       hash, ext2fs_le32_to_cpu(ent[i].block));
 #endif
-               blk = ext2fs_le32_to_cpu(ent[i].block) & 0x0ffffff;
+               blk = ext2fs_le32_to_cpu(ent[i].block) & EXT4_DX_BLOCK_MASK;
                /* Check to make sure the block is valid */
                if (blk >= (blk_t) dx_dir->numblocks) {
                        cd->pctx.blk = blk;
@@ -664,7 +664,8 @@ static void parse_int_node(ext2_filsys fs,
                }
 
                dx_db->previous =
-                       i ? ext2fs_le32_to_cpu(ent[i-1].block & 0x0ffffff) : 0;
+                       i ? (ext2fs_le32_to_cpu(ent[i-1].block) &
+                            EXT4_DX_BLOCK_MASK) : 0;
 
                if (hash < min_hash)
                        min_hash = hash;
index 2496d16dac55009a1ef51959e83edc83513df30f..7d62694138fd5fea54468d4bf0d589794022b8b3 100644 (file)
@@ -232,6 +232,8 @@ struct ext2_dx_root_info {
 
 #define EXT2_HASH_FLAG_INCOMPAT        0x1
 
+#define EXT4_DX_BLOCK_MASK 0x0fffffff
+
 struct ext2_dx_entry {
        __le32 hash;
        __le32 block;