aboutsummaryrefslogtreecommitdiff
path: root/bfd/mach-o.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-12-17 23:21:11 +1030
committerAlan Modra <amodra@gmail.com>2020-12-18 10:34:16 +1030
commit7fbd5f4e2c143bbe28715608ca00e2e93a7d7fd4 (patch)
treef6bc1211e0cdaecc93850eae7a46b305632c0035 /bfd/mach-o.c
parentbd38246a45dc199ce32b50878670bbbdf7e27ad5 (diff)
downloadfsf-binutils-gdb-7fbd5f4e2c143bbe28715608ca00e2e93a7d7fd4.zip
fsf-binutils-gdb-7fbd5f4e2c143bbe28715608ca00e2e93a7d7fd4.tar.gz
fsf-binutils-gdb-7fbd5f4e2c143bbe28715608ca00e2e93a7d7fd4.tar.bz2
Remove some static buffers
Fixes possible overflow of a static buffer for powerpc with translated messages, and on v850 when symbol names are large. * archive.c (_bfd_ar_spacepad, _bfd_ar_sizepad): Use auto buf. * coff-mcore.c (coff_mcore_relocate_section): Likewise. * elf32-ppc.c (ppc_elf_unhandled_reloc): Use asprintf in place of fixed size and possibly too small buf for translated message. * elf64-ppc.c (ppc64_elf_unhandled_reloc): Likewise. * elf32-v850.c (v850_elf_check_relocs): Likewise. * ecoff.c (ecoff_type_to_string): Pass in return string buff rather than using static buffer2. Delete dead code. Remove unnecessary parentheses. (_bfd_ecoff_print_symbol): Pass auto buff to ecoff_type_to_string. * elf32-rx.c (describe_flags): Pass in return string buf rather than using static buf. (rx_elf_merge_private_bfd_data): Pass buf to describe_flags. (rx_elf_print_private_bfd_data): Likewise. * mach-o.c (cpusubtype): Pass in return string buffer rather than using static buffer. (bfd_mach_o_bfd_print_private_bfd_data): Pass buff to cpusubtype. * opncls.c (separate_debug_file_exists): Make buffer an auto var. (bfd_fill_in_gnu_debuglink_section): Likewise. * peXXigen.c (rsrc_resource_name): Pass in return string buffer rather than using static buffer. (rsrc_sort_entries): Pass buff to rsrc_resource_name. * vms-alpha.c (_bfd_vms_write_emh): Pass tbuf to get_vms_time_string. * vms-misc.c (get_vms_time_string): Pass in return string tbuf rather than using static tbuf. * vms.h (get_vms_time_string): Update prototype.
Diffstat (limited to 'bfd/mach-o.c')
-rw-r--r--bfd/mach-o.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/bfd/mach-o.c b/bfd/mach-o.c
index f285305..25ae21d 100644
--- a/bfd/mach-o.c
+++ b/bfd/mach-o.c
@@ -618,10 +618,8 @@ cputype (unsigned long value)
}
static const char *
-cpusubtype (unsigned long cpu_type, unsigned long cpu_subtype)
+cpusubtype (unsigned long cpu_type, unsigned long cpu_subtype, char *buffer)
{
- static char buffer[128];
-
buffer[0] = 0;
switch (cpu_subtype & BFD_MACH_O_CPU_SUBTYPE_MASK)
{
@@ -695,13 +693,14 @@ bfd_mach_o_bfd_print_private_bfd_data (bfd *abfd, void *ptr)
{
FILE * file = (FILE *) ptr;
bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
+ char buff[128];
fprintf (file, _(" MACH-O header:\n"));
fprintf (file, _(" magic: %#lx\n"), (long) mdata->header.magic);
fprintf (file, _(" cputype: %#lx (%s)\n"), (long) mdata->header.cputype,
cputype (mdata->header.cputype));
fprintf (file, _(" cpusubtype: %#lx%s\n"), (long) mdata->header.cpusubtype,
- cpusubtype (mdata->header.cputype, mdata->header.cpusubtype));
+ cpusubtype (mdata->header.cputype, mdata->header.cpusubtype, buff));
fprintf (file, _(" filetype: %#lx\n"), (long) mdata->header.filetype);
fprintf (file, _(" ncmds: %#lx\n"), (long) mdata->header.ncmds);
fprintf (file, _(" sizeocmds: %#lx\n"), (long) mdata->header.sizeofcmds);