aboutsummaryrefslogtreecommitdiff
path: root/bfd/coff-i386.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2014-11-10 14:18:45 +0000
committerNick Clifton <nickc@redhat.com>2014-11-10 14:27:38 +0000
commit36e9d67b868c85232ab630514260f0d9c9c6b27b (patch)
tree62b5f40c0cc1529cb235b367c505804dc4bfcd71 /bfd/coff-i386.c
parentb1f28d992c916eab861df3fa62d436755f874b62 (diff)
downloadbinutils-36e9d67b868c85232ab630514260f0d9c9c6b27b.zip
binutils-36e9d67b868c85232ab630514260f0d9c9c6b27b.tar.gz
binutils-36e9d67b868c85232ab630514260f0d9c9c6b27b.tar.bz2
More fixes for problems exposed by valgrind and the address sanitizer
when displaying the contents of corrupt files. PR binutils/17521 * coff-i386.c (NUM_HOWTOS): New define. (RTYPE2HOWTO): Use it. (coff_i386_rtype_to_howto): Likewise. (coff_i386_reloc_name_lookup): Likewise. (CALC_ADDEND): Check that reloc r_type field is valid. * coff-x86_64.c (NUM_HOWTOS): New define. (RTYPE2HOWTO): Use it. (coff_amd64_rtype_to_howto): Likewise. (coff_amd64_reloc_name_lookup): Likewise. (CALC_ADDEND): Check that reloc r_type field is valid. * coffcode.h (coff_slurp_line_table): Check for symbol table indexing underflow. (coff_slurp_symbol_table): Use zalloc to ensure that all table entries are initialised. * coffgen.c (_bfd_coff_read_string_table): Initialise unused bits in the string table. Also ensure that the table is 0 terminated. (coff_get_normalized_symtab): Check for symbol table indexing underflow. * opncls.c (bfd_alloc): Catch the case where a small negative size can result in only 1 byte being allocated. (bfd_alloc2): Use bfd_alloc. * pe-mips.c (NUM_HOWTOS): New define. (coff_mips_reloc_name_lookup): Use it. (CALC_ADDEND): Check that reloc r_type field is valid. * peXXigen.c (_bfd_XXi_swap_aouthdr_in): Initialise unused entries in the DataDirectory. (pe_print_idata): Avoid reading beyond the end of the data block wen printing strings. (pe_print_edata): Likewise. Check for table indexing underflow. * peicode.h (pe_mkobject): Initialise the pe_opthdr field. (pe_bfd_object_p): Allocate and initialize enough space to hold a PEAOUTHDR, even if the opt_hdr field specified less.
Diffstat (limited to 'bfd/coff-i386.c')
-rw-r--r--bfd/coff-i386.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/bfd/coff-i386.c b/bfd/coff-i386.c
index 87b014b..848d69b 100644
--- a/bfd/coff-i386.c
+++ b/bfd/coff-i386.c
@@ -340,16 +340,18 @@ static reloc_howto_type howto_table[] =
PCRELOFFSET) /* pcrel_offset */
};
+#define NUM_HOWTOS (sizeof (howto_table) / sizeof (howto_table[0]))
+
/* Turn a howto into a reloc nunmber */
#define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
#define BADMAG(x) I386BADMAG(x)
#define I386 1 /* Customize coffcode.h */
-#define RTYPE2HOWTO(cache_ptr, dst) \
- ((cache_ptr)->howto = \
- ((dst)->r_type < sizeof (howto_table) / sizeof (howto_table[0]) \
- ? howto_table + (dst)->r_type \
+#define RTYPE2HOWTO(cache_ptr, dst) \
+ ((cache_ptr)->howto = \
+ ((dst)->r_type < NUM_HOWTOS \
+ ? howto_table + (dst)->r_type \
: NULL))
/* For 386 COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
@@ -386,7 +388,8 @@ static reloc_howto_type howto_table[] =
cache_ptr->addend = - (ptr->section->vma + ptr->value); \
else \
cache_ptr->addend = 0; \
- if (ptr && howto_table[reloc.r_type].pc_relative) \
+ if (ptr && reloc.r_type < NUM_HOWTOS \
+ && howto_table[reloc.r_type].pc_relative) \
cache_ptr->addend += asect->vma; \
}
@@ -438,7 +441,7 @@ coff_i386_rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
{
reloc_howto_type *howto;
- if (rel->r_type >= sizeof (howto_table) / sizeof (howto_table[0]))
+ if (rel->r_type >= NUM_HOWTOS)
{
bfd_set_error (bfd_error_bad_value);
return NULL;
@@ -574,7 +577,7 @@ coff_i386_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
{
unsigned int i;
- for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
+ for (i = 0; i < NUM_HOWTOS; i++)
if (howto_table[i].name != NULL
&& strcasecmp (howto_table[i].name, r_name) == 0)
return &howto_table[i];