:: commit 12983f327b69f3cbddefca484ae7358ba570058f

mintsuki <mintsuki@protonmail.com> — 2020-10-24 13:27

parents: ef1fa256bf

Fix bug in elf lib where a very large buffer could be accidentally allocated on the stack

diff --git a/limine.bin b/limine.bin
index cdba3a9b..108e1c6a 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2/lib/elf.c b/stage2/lib/elf.c
index 2d65bad4..afefe97b 100644
--- a/stage2/lib/elf.c
+++ b/stage2/lib/elf.c
@@ -206,7 +206,7 @@ int elf64_load_section(struct file_handle *fd, void *buffer, const char *name, s
     fread(fd, &shstrtab, hdr.shoff + hdr.shstrndx * sizeof(struct elf64_shdr),
             sizeof(struct elf64_shdr));
 
-    char names[shstrtab.sh_size];
+    char *names = ext_mem_alloc(shstrtab.sh_size);
     fread(fd, names, shstrtab.sh_offset, shstrtab.sh_size);
 
     for (uint16_t i = 0; i < hdr.sh_num; i++) {
@@ -250,7 +250,7 @@ int elf32_load_section(struct file_handle *fd, void *buffer, const char *name, s
     fread(fd, &shstrtab, hdr.shoff + hdr.shstrndx * sizeof(struct elf32_shdr),
             sizeof(struct elf32_shdr));
 
-    char names[shstrtab.sh_size];
+    char *names = ext_mem_alloc(shstrtab.sh_size);
     fread(fd, names, shstrtab.sh_offset, shstrtab.sh_size);
 
     for (uint16_t i = 0; i < hdr.sh_num; i++) {
tab: 248 wrap: offon