:: commit 05e8144c9bdf0196dd2b56771bcf2d97c75cdbb8

Mintsuki <mintsuki@protonmail.com> — 2026-04-14 00:12

parents: 3042d4fa74

lib/elf: Avoid undefined pointer arithmetic in relocation patching

diff --git a/common/lib/elf.c b/common/lib/elf.c
index 9dd81f6f..50c851ad 100644
--- a/common/lib/elf.c
+++ b/common/lib/elf.c
@@ -513,7 +513,7 @@ end_of_pt_segment:
             continue;
 
         // It's inside it, calculate where it is
-        uint64_t *ptr = (uint64_t *)((buffer - vaddr) + relocation->r_addr);
+        uint64_t *ptr = (uint64_t *)(buffer + (relocation->r_addr - vaddr));
 
         switch (relocation->r_info) {
 #if defined (__x86_64__) || defined (__i386__)
tab: 248 wrap: offon