From c799eddb3512a4ce2b5c11bd91f888f30241faf6 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Tue, 13 Dec 2022 10:05:17 +1030 Subject: asan: mips_hi16_list segfault in bfd_get_section_limit_octets static variables like mips_hi16_list are nasty for applications using bfd. It is possible when opening and closing bfds with mis-matched hi/lo relocs to leave a stale section pointer on the list. That can cause a segfault if multiple bfds are being processed. Tidying the list when closing is sufficient to stop this happening (and fixes small memory leaks). This patch goes further and moves mips_hi16_list to where it belongs in the bfd tdata. * elf32-mips.c (bfd_elf32_close_and_cleanup(: Define. * elf64-mips.c (bfd_elf64_close_and_cleanup): Define. * elfn32-mips.c (bfd_elf32_close_and_cleanup(: Define. * elfxx-mips.c (struct mips_hi16): Move earlier. (mips_hi16_list): Move to.. (struct mips_elf_obj_tdata): ..here. (_bfd_mips_elf_close_and_cleanup): New function. (_bfd_mips_elf_hi16_reloc, _bfd_mips_elf_lo16_reloc), (_bfd_elf_mips_get_relocated_section_contents): Adjust uses of mips_hi16_list. * elfxx-mips.h (_bfd_mips_elf_close_and_cleanup): Declare. --- bfd/elf32-mips.c | 1 + 1 file changed, 1 insertion(+) (limited to 'bfd/elf32-mips.c') diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c index be28d1a..0ffa901 100644 --- a/bfd/elf32-mips.c +++ b/bfd/elf32-mips.c @@ -2599,6 +2599,7 @@ static const struct ecoff_debug_swap mips_elf32_ecoff_debug_swap = { _bfd_mips_elf_print_private_bfd_data #define bfd_elf32_bfd_relax_section _bfd_mips_elf_relax_section #define bfd_elf32_mkobject _bfd_mips_elf_mkobject +#define bfd_elf32_close_and_cleanup _bfd_mips_elf_close_and_cleanup /* Support for SGI-ish mips targets. */ #define TARGET_LITTLE_SYM mips_elf32_le_vec -- cgit v1.1