asan: invalid free in bfd_init_section_compress_status
authorAlan Modra <amodra@gmail.com>
Tue, 10 Oct 2023 07:46:38 +0000 (18:16 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 10 Oct 2023 11:47:29 +0000 (22:17 +1030)
commit322b071c45d5e5ae14d247e8fa74a4cff58e1a8a
tree01e4f845ca2116b6487d2a57a0ccc446d6abbee7
parent4825fd2d3552a047264a1f3d900ce30047a8c5f6
asan: invalid free in bfd_init_section_compress_status

With specially crafted compressed sections, it's possible to tickle a
problem when decompressing:  If the compression headers says the
uncompressed size is zero, this will be seen as an error return from
bfd_compress_section_contents.  On errors the caller should free any
malloc'd input buffers, but this isn't really an error and the section
contents have been updated to a bfd_alloc'd buffer which can't be
freed.

* compress.c (bfd_compress_section_contents): Return -1 as error
rather than 0.
(bfd_init_section_compress_status, bfd_compress_section): Adjust.
bfd/compress.c