fs/ntfs3: Fix wrong if in hdr_first_de
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Tue, 11 Oct 2022 17:15:28 +0000 (20:15 +0300)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Mon, 14 Nov 2022 16:50:48 +0000 (19:50 +0300)
We need to check used bytes instead of total.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/ntfs.h

index 9f764bf4ed0a08d2bf78e9fe427b366089af7364..86ea1826d0998065f22e3f4104e41bba13f758d5 100644 (file)
@@ -714,12 +714,13 @@ static inline struct NTFS_DE *hdr_first_de(const struct INDEX_HDR *hdr)
 {
        u32 de_off = le32_to_cpu(hdr->de_off);
        u32 used = le32_to_cpu(hdr->used);
-       struct NTFS_DE *e = Add2Ptr(hdr, de_off);
+       struct NTFS_DE *e;
        u16 esize;
 
-       if (de_off >= used || de_off >= le32_to_cpu(hdr->total))
+       if (de_off >= used || de_off + sizeof(struct NTFS_DE) > used )
                return NULL;
 
+       e = Add2Ptr(hdr, de_off);
        esize = le16_to_cpu(e->size);
        if (esize < sizeof(struct NTFS_DE) || de_off + esize > used)
                return NULL;