]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Sanity check reloc count in get_reloc_upper_bound
authorAlan Modra <amodra@gmail.com>
Thu, 10 Nov 2022 01:18:01 +0000 (11:48 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 10 Nov 2022 09:59:03 +0000 (20:29 +1030)
commita3eb71adfea201f9e14980d8a96ea2e27ef52ad1
tree2bba83828745cc3cf61d2f23ffd81fde8b7aedd0
parentf735116b3fb6dc30912e969d6e8c1b15bbaef510
Sanity check reloc count in get_reloc_upper_bound

The idea here is the stop tools from allocating up to 32G per section
for the arelent pointer array, only to find a little later that the
section reloc count was fuzzed.  This usually doesn't hurt much (on
systems that allow malloc overcommit) except when compiled with asan.

We already do this for ELF targets, and while fixing the logic
recently I decided other targets ought to do the same.

* elf64-sparc.c (elf64_sparc_get_reloc_upper_bound): Sanity check
section reloc count against file size.
* mach-o.c (bfd_mach_o_get_reloc_upper_bound): Likewise.
* aoutx.h (get_reloc_upper_bound): Likewise, and don't duplicate
check done in bfd_get_reloc_upper_bound.
* pdp11.c (get_reloc_upper_bound): Likewise.
* coffgen.c (coff_get_reloc_upper_bound): Likewise.
bfd/aoutx.h
bfd/coffgen.c
bfd/elf64-sparc.c
bfd/mach-o.c
bfd/pdp11.c