:: commit 77a8af1d0a70a9ea4332ebc5314226d48bbfa1f9

mintsuki <mintsuki@protonmail.com> — 2024-06-02 22:14

parents: 6b1e6d88dd

lib/elf: More sound calculation of relocs_i

diff --git a/common/lib/elf.c b/common/lib/elf.c
index 8f0153f2..74035d42 100644
--- a/common/lib/elf.c
+++ b/common/lib/elf.c
@@ -281,7 +281,10 @@ static bool elf64_apply_relocations(uint8_t *elf, struct elf64_hdr *hdr, void *b
             }
         }
 
-        size_t relocs_i = rela_size / rela_ent + dt_pltrelsz / rela_ent;
+        size_t relocs_i = rela_size / rela_ent;
+        if (dt_jmprel != 0) {
+            relocs_i += dt_pltrelsz / rela_ent;
+        }
         struct elf64_rela **relocs = ext_mem_alloc(relocs_i * sizeof(struct elf64_rela *));
 
         for (uint64_t j = 0, offset = 0; offset < rela_size; offset += rela_ent) {
tab: 248 wrap: offon