From 30814dfacfa527c514914d9e8b84a307e2c53890 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sat, 13 Feb 2021 00:35:29 +0100 Subject: [PATCH] Don't use stale section data pointers put_elf_reloca might reallocate the section into which we point, so don't remember the pointer just the offset. --- tccgen.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tccgen.c b/tccgen.c index b7f9e139..0e62a0ec 100644 --- a/tccgen.c +++ b/tccgen.c @@ -8034,10 +8034,10 @@ static void init_putv(init_params *p, CType *type, unsigned long c) includes relocations. Use the fact that relocs are created it order, so look from the end of relocs until we hit one before the copied region. */ - int num_relocs = ssec->reloc->data_offset / sizeof(*rel); - rel = (ElfW_Rel*)(ssec->reloc->data + ssec->reloc->data_offset); - while (num_relocs--) { - rel--; + unsigned long relofs = ssec->reloc->data_offset; + while (relofs >= sizeof(*rel)) { + relofs -= sizeof(*rel); + rel = (ElfW_Rel*)(ssec->reloc->data + relofs); if (rel->r_offset >= esym->st_value + size) continue; if (rel->r_offset < esym->st_value)