som: buffer overflow writing strings
authorAlan Modra <amodra@gmail.com>
Fri, 25 Aug 2023 06:10:10 +0000 (15:40 +0930)
committerAlan Modra <amodra@gmail.com>
Fri, 25 Aug 2023 06:25:25 +0000 (15:55 +0930)
commitb73ffa23bf6ed7f48ce67881d97b4111ce3b8181
treec7435f1bfef7384eaf04af4118df91d0fd367c53
parentd537f77ef3b18a5fbfd598643aaad957652e9608
som: buffer overflow writing strings

Code in som_write_symbol_strings neglected to allow for padding, which
can result in a buffer overflow.  It also used xrealloc, which we're
not supposed to use in libbfd because libbfd isn't supposed to call
exit.  Also a realloc is perhaps not a good idea when none of the
buffer contents are needed, so replace with free, bfd_malloc.  There
were three copies of the string handling code, so rather than fix them
all I've extracted them to a function.  This necessitated making one
of the fields in struct som_symbol unsigned.

* som.c (add_string): New function.
(som_write_space_strings, som_write_symbol_strings): Use it.
* som.h (som_symbol_type <stringtab_offset>): Make unsigned.
bfd/som.c
bfd/som.h