From 8c83a4851da1c7eda83098ade238665b15774da3 Mon Sep 17 00:00:00 2001
From: Dan Carpenter <dan.carpenter@oracle.com>
Date: Tue, 24 Aug 2021 10:50:15 +0300
Subject: [Backport 8c83a4851da1] src: Potential NULL dereference in
hdr_find_split()
The "e" pointer is dereferenced before it has been checked for NULL.
Move the dereference after the NULL check to prevent an Oops.
Fixes: 82cae269cfa9 ("src: Add initialization of super block")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
src/index.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/index.c b/src/index.c
index 5fb41c9c89100aee4d6d0e8f7cf65556aec11250..f4729aa50671f27de961305744b3839588696108 100644
--- a/src/index.c
+++ b/src/index.c
@@ -557,11 +557,12 @@ static const struct NTFS_DE *hdr_find_split(const struct INDEX_HDR *hdr)
size_t o;
const struct NTFS_DE *e = hdr_first_de(hdr);
u32 used_2 = le32_to_cpu(hdr->used) >> 1;
- u16 esize = le16_to_cpu(e->size);
+ u16 esize;
if (!e || de_is_last(e))
return NULL;
+ esize = le16_to_cpu(e->size);
for (o = le32_to_cpu(hdr->de_off) + esize; o < used_2; o += esize) {
const struct NTFS_DE *p = e;
--
2.31.1