Whamcloud - gitweb
libext2fs: fix endian handling of ext3_extent_header
authorEric Sandeen <sandeen@redhat.com>
Thu, 23 Oct 2014 21:27:32 +0000 (16:27 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 4 Nov 2014 16:12:45 +0000 (11:12 -0500)
This turned up when trying to resize a filesystem containing
a file with many extents on PPC64.

Fix all locations where ext3_extent_header members aren't
handled in an endian-safe manner.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
lib/ext2fs/ext3_extents.h

index 88fabc9..fcf4d86 100644 (file)
@@ -95,15 +95,20 @@ struct ext3_ext_path {
        ((struct ext3_extent_idx *) (((char *) (__hdr__)) +     \
                                     sizeof(struct ext3_extent_header)))
 #define EXT_HAS_FREE_INDEX(__path__) \
-       ((__path__)->p_hdr->eh_entries < (__path__)->p_hdr->eh_max)
+       (ext2fs_le16_to_cpu((__path__)->p_hdr->eh_entries) < \
+        ext2fs_le16_to_cpu((__path__)->p_hdr->eh_max))
 #define EXT_LAST_EXTENT(__hdr__) \
-       (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->eh_entries - 1)
+       (EXT_FIRST_EXTENT((__hdr__)) + \
+       ext2fs_le16_to_cpu((__hdr__)->eh_entries) - 1)
 #define EXT_LAST_INDEX(__hdr__) \
-       (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->eh_entries - 1)
+       (EXT_FIRST_INDEX((__hdr__)) + \
+       ext2fs_le16_to_cpu((__hdr__)->eh_entries) - 1)
 #define EXT_MAX_EXTENT(__hdr__) \
-       (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->eh_max - 1)
+       (EXT_FIRST_EXTENT((__hdr__)) + \
+       ext2fs_le16_to_cpu((__hdr__)->eh_max) - 1)
 #define EXT_MAX_INDEX(__hdr__) \
-       (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->eh_max - 1)
+       (EXT_FIRST_INDEX((__hdr__)) + \
+       ext2fs_le16_to_cpu((__hdr__)->eh_max) - 1)
 
 #endif /* _LINUX_EXT3_EXTENTS */