]> git.corax.cc Git - corax/commitdiff
kernel/core: Make elf_phdr_foreach() calculate the address of the headers correctly
authorMatthias Kruk <m@m10k.eu>
Mon, 4 May 2020 19:20:41 +0000 (04:20 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 4 May 2020 19:20:41 +0000 (04:20 +0900)
kernel/core/elf.c

index b25b7cab490899d901e76c575c8f58d3f4d5a8f6..b516446bef48ab89f1b6a976f6bcd325cfc852ef 100644 (file)
@@ -50,14 +50,16 @@ int elf_phdr_foreach(void *elf, size_t size,
        hdr = (struct elf_hdr*)elf;
 
        if(hdr->e_phoff) {
+               char *phbase;
                int i;
 
                ret_val = 0;
+               phbase = (char*)elf + hdr->e_phoff;
 
                for(i = 0; i < hdr->e_phnum; i++) {
                        struct elf_phdr *phdr;
 
-                       phdr = (struct elf_phdr*)((char*)elf + i * hdr->e_phentsize);
+                       phdr = (struct elf_phdr*)(phbase + i * hdr->e_phentsize);
 
                        ret_val = func(hdr, phdr, arg2);