aboutsummaryrefslogtreecommitdiff
path: root/bfd/ecoff.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/ecoff.c
parentbd38246a45dc199ce32b50878670bbbdf7e27ad5 (diff)
downloadgdb-7fbd5f4e2c143bbe28715608ca00e2e93a7d7fd4.zip
gdb-7fbd5f4e2c143bbe28715608ca00e2e93a7d7fd4.tar.gz
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/ecoff.c')
-rw-r--r--bfd/ecoff.c36
1 files changed, 20 insertions, 16 deletions
diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index 22060e7..798e37a 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -1056,7 +1056,7 @@ ecoff_emit_aggregate (bfd *abfd,
/* Convert the type information to string format. */
static char *
-ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
+ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx, char *buff)
{
union aux_ext *aux_ptr;
int bigendian;
@@ -1071,9 +1071,8 @@ ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
unsigned int basic_type;
int i;
char buffer1[1024];
- static char buffer2[1024];
char *p1 = buffer1;
- char *p2 = buffer2;
+ char *p2 = buff;
RNDXR rndx;
aux_ptr = ecoff_data (abfd)->debug_info.external_aux + fdr->iauxBase;
@@ -1239,7 +1238,7 @@ ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
break;
}
- p1 += strlen (buffer1);
+ p1 += strlen (p1);
/* If this is a bitfield, get the bitsize. */
if (u.ti.fBitfield)
@@ -1248,7 +1247,6 @@ ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
bitsize = AUX_GET_WIDTH (bigendian, &aux_ptr[indx++]);
sprintf (p1, " : %d", bitsize);
- p1 += strlen (buffer1);
}
/* Deal with any qualifiers. */
@@ -1332,7 +1330,7 @@ ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
(long) (qualifiers[j].stride));
else
- sprintf (p2, " {%ld bits}", (long) (qualifiers[j].stride));
+ sprintf (p2, " {%ld bits}", (long) qualifiers[j].stride);
p2 += strlen (p2);
strcpy (p2, "] of ");
@@ -1345,7 +1343,7 @@ ecoff_type_to_string (bfd *abfd, FDR *fdr, unsigned int indx)
}
strcpy (p2, buffer1);
- return buffer2;
+ return buff;
}
/* Return information about ECOFF symbol SYMBOL in RET. */
@@ -1514,13 +1512,16 @@ _bfd_ecoff_print_symbol (bfd *abfd,
if (ECOFF_IS_STAB (&ecoff_ext.asym))
;
else if (ecoffsymbol (symbol)->local)
- /* xgettext:c-format */
- fprintf (file, _("\n End+1 symbol: %-7ld Type: %s"),
- ((long)
- (AUX_GET_ISYM (bigendian,
- &aux_base[ecoff_ext.asym.index])
- + sym_base)),
- ecoff_type_to_string (abfd, fdr, indx + 1));
+ {
+ char buff[1024];
+ /* xgettext:c-format */
+ fprintf (file, _("\n End+1 symbol: %-7ld Type: %s"),
+ ((long)
+ (AUX_GET_ISYM (bigendian,
+ &aux_base[ecoff_ext.asym.index])
+ + sym_base)),
+ ecoff_type_to_string (abfd, fdr, indx + 1, buff));
+ }
else
fprintf (file, _("\n Local symbol: %ld"),
((long) indx
@@ -1546,8 +1547,11 @@ _bfd_ecoff_print_symbol (bfd *abfd,
default:
if (! ECOFF_IS_STAB (&ecoff_ext.asym))
- fprintf (file, _("\n Type: %s"),
- ecoff_type_to_string (abfd, fdr, indx));
+ {
+ char buff[1024];
+ fprintf (file, _("\n Type: %s"),
+ ecoff_type_to_string (abfd, fdr, indx, buff));
+ }
break;
}
}