:: commit bb315e95fdaf9c7a655d9cd7c4f288f61b61d12a

Mintsuki <mintsuki@protonmail.com> — 2026-01-11 21:04

parents: 69050a0916

elf: Validate shstrndx is within section header bounds

diff --git a/common/lib/elf.c b/common/lib/elf.c
index 5382efe2..eb35d513 100644
--- a/common/lib/elf.c
+++ b/common/lib/elf.c
@@ -623,6 +623,10 @@ bool elf64_load_section(uint8_t *elf, void *buffer, const char *name, size_t lim
         panic(true, "elf: shdr_size < sizeof(struct elf64_shdr)");
     }
 
+    if (hdr->shstrndx >= hdr->sh_num) {
+        return false;
+    }
+
     struct elf64_shdr *shstrtab = (void *)elf + (hdr->shoff + hdr->shstrndx * hdr->shdr_size);
 
     char *names = (void *)elf + shstrtab->sh_offset;
tab: 248 wrap: offon