diff options
author | Alan Modra <amodra@gmail.com> | 2021-12-17 15:01:20 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2021-12-17 16:01:34 +1030 |
commit | 7ebf6ed02bde3a488bb588316e47b4df68796076 (patch) | |
tree | db04fb527931fea3b7aada7a43443d8dabdb3056 /bfd/elfxx-mips.c | |
parent | cfabce5ba10ea15158c78bdac732425a46057e42 (diff) | |
download | gdb-7ebf6ed02bde3a488bb588316e47b4df68796076.zip gdb-7ebf6ed02bde3a488bb588316e47b4df68796076.tar.gz gdb-7ebf6ed02bde3a488bb588316e47b4df68796076.tar.bz2 |
asan: use after free in _bfd_elf_mips_get_relocated_section_contents
Leaving entries on mips_hi16_list from a previous pass over relocs
leads to confusing bugs.
* elfxx-mips.c (_bfd_elf_mips_get_relocated_section_contents):
Free mips_hi16_list entries on error exit.
Diffstat (limited to 'bfd/elfxx-mips.c')
-rw-r--r-- | bfd/elfxx-mips.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 4aaa3ea..34005c6 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -13242,7 +13242,26 @@ _bfd_elf_mips_get_relocated_section_contents reloc_vector = (arelent **) bfd_malloc (reloc_size); if (reloc_vector == NULL) - return NULL; + { + struct mips_hi16 **hip, *hi; + error_return: + /* If we are going to return an error, remove entries on + mips_hi16_list that point into this section's data. Data + will typically be freed on return from this function. */ + hip = &mips_hi16_list; + while ((hi = *hip) != NULL) + { + if (hi->input_section == input_section) + { + *hip = hi->next; + free (hi); + } + else + hip = &hi->next; + } + data = NULL; + goto out; + } reloc_count = bfd_canonicalize_reloc (input_bfd, input_section, @@ -13432,12 +13451,9 @@ _bfd_elf_mips_get_relocated_section_contents } } + out: free (reloc_vector); return data; - - error_return: - free (reloc_vector); - return NULL; } static bool |