]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
More fixes for illegal memory accesses triggered by running objdump on fuzzed binaries.
authorNick Clifton <nickc@redhat.com>
Tue, 3 Feb 2015 14:34:54 +0000 (14:34 +0000)
committerNick Clifton <nickc@redhat.com>
Tue, 3 Feb 2015 14:34:54 +0000 (14:34 +0000)
PR binutils/17512
* objdump.c (display_any_bfd): Fail if archives nest too deeply.

* ecoff.c: Use bfd_alloc2 to allocate space for structure arrays.
(_bfd_ecoff_slurp_symbol_table): Check for a negative symbol
index or an out of range fdr index.
* elf-m10300.c (mn10300_info_to_howto): Fix typo in error message.
* elf32-arc.c (arc_info_to_howto_rel): Likewise.
* elf32-avr.c (avr_info_to_howto_rela): Likewise.
* elf32-cr16.c (elf_cr16_info_to_howto): Likewise.
* elf32-cr16c.c (elf_cr16c_info_to_howto_rel): Likewise.
* elf32-cris.c (cris_info_to_howto_rela): Likewise.
* elf32-crx.c (elf_crx_info_to_howto): Likewise.
* elf32-d10v.c (d10v_info_to_howto_rel): Likewise.
* elf32-d30v.c (d30v_info_to_howto_rel): Likewise.
* elf32-epiphany.c (epiphany_info_to_howto_rela): Likewise.
* elf32-fr30.c (fr30_info_to_howto_rela): Likewise.
* elf32-frv.c (frv_info_to_howto_rela): Likewise.
* elf32-i370.c (i370_elf_info_to_howto): Likewise.
* elf32-i960.c (elf32_i960_info_to_howto_rel): Likewise.
* elf32-ip2k.c (ip2k_info_to_howto_rela): Likewise.
* elf32-iq2000.c (iq2000_info_to_howto_rela): Likewise.
* elf32-lm32.c (lm32_info_to_howto_rela): Likewise.
* elf32-m32c.c (m32c_info_to_howto_rela): Likewise.
* elf32-m32r.c (m32r_info_to_howto_rel): Likewise.
* elf32-m68hc11.c (m68hc11_info_to_howto_rel): Likewise.
* elf32-m68hc12.c (m68hc11_info_to_howto_rel): Likewise.
* elf32-mcore.c (mcore_elf_info_to_howto): Likewise.
* elf32-mep.c (mep_info_to_howto_rela): Likewise.
* elf32-metag.c (metag_info_to_howto_rela): Likewise.
* elf32-microblaze.c (microblaze_elf_info_to_howto): Likewise.
* elf32-moxie.c (moxie_info_to_howto_rela): Likewise.
* elf32-msp430.c (msp430_info_to_howto_rela): Likewise.
* elf32-mt.c (mt_info_to_howto_rela): Likewise.
* elf32-nds32.c (nds32_info_to_howto_rel): Likewise.
* elf32-or1k.c (or1k_info_to_howto_rela): Likewise.
* elf32-pj.c (pj_elf_info_to_howto): Likewise.
* elf32-ppc.c (ppc_elf_info_to_howto): Likewise.
* elf32-rl78.c (rl78_info_to_howto_rela): Likewise.
* elf32-rx.c (rx_info_to_howto_rela): Likewise.
* elf32-sh.c (sh_elf_info_to_howto): Likewise.
* elf32-spu.c (spu_elf_info_to_howto): Likewise.
* elf32-v850.c (v850_elf_perform_relocation): Likewise.
* elf32-vax.c (rtype_to_howto): Likewise.
* elf32-visium.c (visium_info_to_howto_rela): Likewise.
* elf32-xgate.c (xgate_info_to_howto_rel): Likewise.
* elf32-xtensa.c (elf_xtensa_info_to_howto_rela): Likewise.
* elf64-alpha.c (elf64_alpha_info_to_howto): Likewise.
* elf64-mmix.c (mmix_info_to_howto_rela): Likewise.
* mach-o.c: Use bfd_alloc2 to allocate space for structure arrays.
(bfd_mach_o_canonicalize_one_reloc): Fix check on out
of range symbol indicies.
(bfd_mach_o_canonicalize_relocs): Check for out of range alloc.
(bfd_mach_o_canonicalize_dynamic_reloc): Likewise.
(bfd_mach_o_build_dysymtab): Likewise.
(bfd_mach_o_write_symtab_content): Set the string table size to
zero upon error.
(bfd_mach_o_read_symtab_symbols): Reset the nsyms value if the
read fails.
* peXXigen.c (pe_print_edata):  Check for numeric overflow in edt
fields.
* tekhex.c (first_phase): Check for src pointer reaching end of
buffer.

50 files changed:
bfd/ChangeLog
bfd/ecoff.c
bfd/elf-m10300.c
bfd/elf32-arc.c
bfd/elf32-avr.c
bfd/elf32-cr16.c
bfd/elf32-cr16c.c
bfd/elf32-cris.c
bfd/elf32-crx.c
bfd/elf32-d10v.c
bfd/elf32-d30v.c
bfd/elf32-epiphany.c
bfd/elf32-fr30.c
bfd/elf32-frv.c
bfd/elf32-i370.c
bfd/elf32-i960.c
bfd/elf32-ip2k.c
bfd/elf32-iq2000.c
bfd/elf32-lm32.c
bfd/elf32-m32c.c
bfd/elf32-m32r.c
bfd/elf32-m68hc11.c
bfd/elf32-m68hc12.c
bfd/elf32-mcore.c
bfd/elf32-mep.c
bfd/elf32-metag.c
bfd/elf32-microblaze.c
bfd/elf32-moxie.c
bfd/elf32-msp430.c
bfd/elf32-mt.c
bfd/elf32-nds32.c
bfd/elf32-or1k.c
bfd/elf32-pj.c
bfd/elf32-ppc.c
bfd/elf32-rl78.c
bfd/elf32-rx.c
bfd/elf32-sh.c
bfd/elf32-spu.c
bfd/elf32-v850.c
bfd/elf32-vax.c
bfd/elf32-visium.c
bfd/elf32-xgate.c
bfd/elf32-xtensa.c
bfd/elf64-alpha.c
bfd/elf64-mmix.c
bfd/mach-o.c
bfd/peXXigen.c
bfd/tekhex.c
binutils/ChangeLog
binutils/objdump.c

index e6ed9b6c6ff34b60883a74d09ef6ec7da2386e48..4924f03ff3b38230a4fa4f1516743e5f920edc98 100644 (file)
@@ -1,3 +1,67 @@
+2015-02-03  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/17512
+       * ecoff.c: Use bfd_alloc2 to allocate space for structure arrays.
+       (_bfd_ecoff_slurp_symbol_table): Check for a negative symbol
+       index or an out of range fdr index.
+       * elf-m10300.c (mn10300_info_to_howto): Fix typo in error message.
+       * elf32-arc.c (arc_info_to_howto_rel): Likewise.
+       * elf32-avr.c (avr_info_to_howto_rela): Likewise.
+       * elf32-cr16.c (elf_cr16_info_to_howto): Likewise.
+       * elf32-cr16c.c (elf_cr16c_info_to_howto_rel): Likewise.
+       * elf32-cris.c (cris_info_to_howto_rela): Likewise.
+       * elf32-crx.c (elf_crx_info_to_howto): Likewise.
+       * elf32-d10v.c (d10v_info_to_howto_rel): Likewise.
+       * elf32-d30v.c (d30v_info_to_howto_rel): Likewise.
+       * elf32-epiphany.c (epiphany_info_to_howto_rela): Likewise.
+       * elf32-fr30.c (fr30_info_to_howto_rela): Likewise.
+       * elf32-frv.c (frv_info_to_howto_rela): Likewise.
+       * elf32-i370.c (i370_elf_info_to_howto): Likewise.
+       * elf32-i960.c (elf32_i960_info_to_howto_rel): Likewise.
+       * elf32-ip2k.c (ip2k_info_to_howto_rela): Likewise.
+       * elf32-iq2000.c (iq2000_info_to_howto_rela): Likewise.
+       * elf32-lm32.c (lm32_info_to_howto_rela): Likewise.
+       * elf32-m32c.c (m32c_info_to_howto_rela): Likewise.
+       * elf32-m32r.c (m32r_info_to_howto_rel): Likewise.
+       * elf32-m68hc11.c (m68hc11_info_to_howto_rel): Likewise.
+       * elf32-m68hc12.c (m68hc11_info_to_howto_rel): Likewise.
+       * elf32-mcore.c (mcore_elf_info_to_howto): Likewise.
+       * elf32-mep.c (mep_info_to_howto_rela): Likewise.
+       * elf32-metag.c (metag_info_to_howto_rela): Likewise.
+       * elf32-microblaze.c (microblaze_elf_info_to_howto): Likewise.
+       * elf32-moxie.c (moxie_info_to_howto_rela): Likewise.
+       * elf32-msp430.c (msp430_info_to_howto_rela): Likewise.
+       * elf32-mt.c (mt_info_to_howto_rela): Likewise.
+       * elf32-nds32.c (nds32_info_to_howto_rel): Likewise.
+       * elf32-or1k.c (or1k_info_to_howto_rela): Likewise.
+       * elf32-pj.c (pj_elf_info_to_howto): Likewise.
+       * elf32-ppc.c (ppc_elf_info_to_howto): Likewise.
+       * elf32-rl78.c (rl78_info_to_howto_rela): Likewise.
+       * elf32-rx.c (rx_info_to_howto_rela): Likewise.
+       * elf32-sh.c (sh_elf_info_to_howto): Likewise.
+       * elf32-spu.c (spu_elf_info_to_howto): Likewise.
+       * elf32-v850.c (v850_elf_perform_relocation): Likewise.
+       * elf32-vax.c (rtype_to_howto): Likewise.
+       * elf32-visium.c (visium_info_to_howto_rela): Likewise.
+       * elf32-xgate.c (xgate_info_to_howto_rel): Likewise.
+       * elf32-xtensa.c (elf_xtensa_info_to_howto_rela): Likewise.
+       * elf64-alpha.c (elf64_alpha_info_to_howto): Likewise.
+       * elf64-mmix.c (mmix_info_to_howto_rela): Likewise.
+       * mach-o.c: Use bfd_alloc2 to allocate space for structure arrays.
+       (bfd_mach_o_canonicalize_one_reloc): Fix check on out
+       of range symbol indicies.
+       (bfd_mach_o_canonicalize_relocs): Check for out of range alloc.
+       (bfd_mach_o_canonicalize_dynamic_reloc): Likewise.
+       (bfd_mach_o_build_dysymtab): Likewise.
+       (bfd_mach_o_write_symtab_content): Set the string table size to
+       zero upon error.
+       (bfd_mach_o_read_symtab_symbols): Reset the nsyms value if the
+       read fails.
+       * peXXigen.c (pe_print_edata):  Check for numeric overflow in edt
+       fields.
+       * tekhex.c (first_phase): Check for src pointer reaching end of
+       buffer.
+
 2015-02-03  Will Newton  <will.newton@linaro.org>
 
        * elfnn-aarch64.c (elfNN_aarch64_finish_dynamic_symbol):
index 504d6b987f4637cbf290f827914f52d1b31d014e..a8ba28a30e66ef4f601bb6f08a5e8b594e734ccc 100644 (file)
@@ -504,7 +504,6 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
   struct fdr *fdr_ptr;
   bfd_size_type raw_end;
   bfd_size_type cb_end;
-  bfd_size_type amt;
   file_ptr pos;
 
   BFD_ASSERT (debug == &ecoff_data (abfd)->debug_info);
@@ -607,9 +606,8 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
 
      We need to look at the fdr to deal with a lot of information in
      the symbols, so we swap them here.  */
-  amt = internal_symhdr->ifdMax;
-  amt *= sizeof (struct fdr);
-  debug->fdr = (FDR *) bfd_alloc (abfd, amt);
+  debug->fdr = (FDR *) bfd_alloc2 (abfd, internal_symhdr->ifdMax,
+                                  sizeof (struct fdr));
   if (debug->fdr == NULL)
     return FALSE;
   external_fdr_size = backend->debug_swap.external_fdr_size;
@@ -859,7 +857,6 @@ _bfd_ecoff_slurp_symbol_table (bfd *abfd)
     = backend->debug_swap.swap_ext_in;
   void (* const swap_sym_in) (bfd *, void *, SYMR *)
     = backend->debug_swap.swap_sym_in;
-  bfd_size_type internal_size;
   ecoff_symbol_type *internal;
   ecoff_symbol_type *internal_ptr;
   char *eraw_src;
@@ -878,9 +875,8 @@ _bfd_ecoff_slurp_symbol_table (bfd *abfd)
   if (bfd_get_symcount (abfd) == 0)
     return TRUE;
 
-  internal_size = bfd_get_symcount (abfd);
-  internal_size *= sizeof (ecoff_symbol_type);
-  internal = (ecoff_symbol_type *) bfd_alloc (abfd, internal_size);
+  internal = (ecoff_symbol_type *) bfd_alloc2 (abfd, bfd_get_symcount (abfd),
+                                              sizeof (ecoff_symbol_type)); 
   if (internal == NULL)
     return FALSE;
 
@@ -896,20 +892,28 @@ _bfd_ecoff_slurp_symbol_table (bfd *abfd)
       (*swap_ext_in) (abfd, (void *) eraw_src, &internal_esym);
 
       /* PR 17512: file: 3372-1000-0.004.  */
-      if (internal_esym.asym.iss >= ecoff_data (abfd)->debug_info.symbolic_header.issExtMax)
+      if (internal_esym.asym.iss >= ecoff_data (abfd)->debug_info.symbolic_header.issExtMax
+         || internal_esym.asym.iss < 0)
        return FALSE;
 
       internal_ptr->symbol.name = (ecoff_data (abfd)->debug_info.ssext
                                   + internal_esym.asym.iss);
+
       if (!ecoff_set_symbol_info (abfd, &internal_esym.asym,
                                  &internal_ptr->symbol, 1,
                                  internal_esym.weakext))
        return FALSE;
-      
+
       /* The alpha uses a negative ifd field for section symbols.  */
       if (internal_esym.ifd >= 0)
-       internal_ptr->fdr = (ecoff_data (abfd)->debug_info.fdr
-                            + internal_esym.ifd);
+       {
+         /* PR 17512: file: 3372-1983-0.004.  */
+         if (internal_esym.ifd >= ecoff_data (abfd)->debug_info.symbolic_header.ifdMax)
+           internal_ptr->fdr = NULL;
+         else
+           internal_ptr->fdr = (ecoff_data (abfd)->debug_info.fdr
+                                + internal_esym.ifd);
+       }
       else
        internal_ptr->fdr = NULL;
       internal_ptr->local = FALSE;
index acb21ff0f39f103bb133c2a412201a8327c249d5..a6a22b354e8ba59b484df72537631441df02cf5f 100644 (file)
@@ -808,7 +808,7 @@ mn10300_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= R_MN10300_MAX)
     {
-      (*_bfd_error_handler) (_("%A: unrecognised MN10300 reloc number: %d"),
+      (*_bfd_error_handler) (_("%B: unrecognised MN10300 reloc number: %d"),
                             abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
       r_type = R_MN10300_NONE;
index ef71b256ae63f1a02c4af3d7e8a26008df40df84..07af56b5bf06455e8957146f9751e0fd27195c99 100644 (file)
@@ -174,7 +174,7 @@ arc_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_ARC_max)
     {
-      _bfd_error_handler (_("%A: invalid ARC reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid ARC reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &elf_arc_howto_table[r_type];
index c88b6aafd52f0341f3c1aa7971a5b66921c731d3..255a2c2c070c34709922dddc5e69a846733d8350 100644 (file)
@@ -861,7 +861,7 @@ avr_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_AVR_max)
     {
-      _bfd_error_handler (_("%A: invalid AVR reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid AVR reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &elf_avr_howto_table[r_type];
index 23ced9e29295ff4610fb1e83ec39f6f302d4605a..047d720575d00468b64a15388487c9dc35b6dbc4 100644 (file)
@@ -675,7 +675,7 @@ elf_cr16_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
 
   if (r_type >= R_CR16_MAX)
     {
-      (*_bfd_error_handler) (_("%A: unrecognised CR16 reloc number: %d"),
+      (*_bfd_error_handler) (_("%B: unrecognised CR16 reloc number: %d"),
                             abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
       r_type = R_CR16_NONE;
index db908f0a4a83ad02786756c4592457150701b053..6547ec142e39c62efc3b791013c5afc87fc61ef3 100644 (file)
@@ -182,7 +182,7 @@ elf_cr16c_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
 
   if (r_type >= RINDEX_16C_MAX)
     {
-      _bfd_error_handler (_("%A; invalid CR16C reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid CR16C reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &elf_howto_table[r_type];
index 46f51694f6ff15d281bdc2b28f483cd4ffefc1ec..d5670ac610a4bb55551231d2de7691e17205c2fe 100644 (file)
@@ -463,7 +463,7 @@ cris_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= R_CRIS_max)
     {
-      _bfd_error_handler (_("%A: invalid CRIS reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid CRIS reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = & cris_elf_howto_table [r_type];
index 2b6411decb2be0c6ece18e60ff2678216987f72c..0f9069c8b79673d3e2f092830d1349371a4ba52e 100644 (file)
@@ -425,7 +425,7 @@ elf_crx_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
   unsigned int r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= R_CRX_MAX)
     {
-      (*_bfd_error_handler) (_("%A: unrecognised CRX reloc number: %d"),
+      (*_bfd_error_handler) (_("%B: unrecognised CRX reloc number: %d"),
                             abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
       r_type = R_CRX_NONE;
index 951f7f56440846584a3b624095241deefe5425e6..a7d30c9584cda22748b179d56292db7213f134d9 100644 (file)
@@ -230,7 +230,7 @@ d10v_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_D10V_max)
     {
-      _bfd_error_handler (_("%A: invalid D10V reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid D10V reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &elf_d10v_howto_table[r_type];
index fdf44ecd9df7b387a759283902eab3450378a15a..3976206edff45a62134cdc39d1b1d13e9c6cd75e 100644 (file)
@@ -518,7 +518,7 @@ d30v_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_D30V_max)
     {
-      _bfd_error_handler (_("%A: invalid D30V reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid D30V reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &elf_d30v_howto_table[r_type];
@@ -536,7 +536,7 @@ d30v_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_D30V_max)
     {
-      _bfd_error_handler (_("%A: invalid D30V reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid D30V reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &elf_d30v_howto_table[r_type];
index bd640ae21a5727da2d9fa602fd1365045abdd597..6c576836113dfe3e6f8683a58b6f89b86d5d0004 100644 (file)
@@ -372,7 +372,7 @@ epiphany_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_EPIPHANY_max)
     {
-      _bfd_error_handler (_("%A: invalid Epiphany reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid Epiphany reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = & epiphany_elf_howto_table [r_type];
index ba47a3d3f8a1f4a339c41f1025497a98413e007c..13f6f19911dd286f93c5baff11f7ce4c6f616311 100644 (file)
@@ -377,7 +377,7 @@ fr30_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_FR30_max)
     {
-      _bfd_error_handler (_("%A: invalid FR30 reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid FR30 reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = & fr30_elf_howto_table [r_type];
index deaa2e31803a429e2fef6a0edea3006556fb8eb3..f374df0828484ee8826f72dd2cf3fe5b1b1dacfb 100644 (file)
@@ -2559,7 +2559,7 @@ frv_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
     default:
       if (r_type >= (unsigned int) R_FRV_max)
        {
-         _bfd_error_handler (_("%A: invalid FRV reloc number: %d"), abfd, r_type);
+         _bfd_error_handler (_("%B: invalid FRV reloc number: %d"), abfd, r_type);
          r_type = 0;
        }
       cache_ptr->howto = & elf32_frv_howto_table [r_type];
index 7d92fe546641ad28844591ef5046edb0120e43ff..6e6c8e837b90b9f2ce7dac855a8d39302327c8eb 100644 (file)
@@ -303,7 +303,7 @@ i370_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= R_I370_max)
     {
-      (*_bfd_error_handler) (_("%A: unrecognised I370 reloc number: %d"),
+      (*_bfd_error_handler) (_("%B: unrecognised I370 reloc number: %d"),
                             abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
       r_type = R_I370_NONE;
index 978f2a1bba9004db6a0e7c439dbfd17a8055a0ee..ff51bcdae01763b7d5a3db0f8157cd55f0d4b221 100644 (file)
@@ -136,7 +136,7 @@ elf32_i960_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   /* PR 17521: file: 9609b8d6.  */
   if (type >= R_960_max)
     {
-      _bfd_error_handler (_("%A; invalid i960 reloc number: %d"), abfd, type);
+      _bfd_error_handler (_("%B: invalid i960 reloc number: %d"), abfd, type);
       type = 0;
     }
 
index c06860df1233da3a21627846ad56d5a83a4123a4..1379446c187ee773627827ecbdbb7d94bb8a66d7 100644 (file)
@@ -1241,7 +1241,7 @@ ip2k_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_IP2K_max)
     {
-      _bfd_error_handler (_("%A: invalid IP2K reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid IP2K reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = & ip2k_elf_howto_table [r_type];
index 500dcd413cf55c9019c6c8d8069a6ce4dc9f5545..ef43595182a09c146a627c5f9aab76ed1b16e832 100644 (file)
@@ -437,7 +437,7 @@ iq2000_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED,
     default:
       if (r_type >= (unsigned int) R_IQ2000_max)
        {
-         _bfd_error_handler (_("%A: invalid IQ2000 reloc number: %d"), abfd, r_type);
+         _bfd_error_handler (_("%B: invalid IQ2000 reloc number: %d"), abfd, r_type);
          r_type = 0;
        }
       cache_ptr->howto = & iq2000_elf_howto_table [r_type];
index 6aca84842b6ab318f8e18a4e89b76605cb89954e..0c01e08df36c0dcfabfe106d5f27ccca7688284e 100644 (file)
@@ -590,7 +590,7 @@ lm32_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_LM32_max)
     {
-      _bfd_error_handler (_("%A: invalid LM32 reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid LM32 reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &lm32_elf_howto_table[r_type];
index 75725811599b05d6c24277ca420b8228caa03a47..70e9174e9be39f26377360e32e953dfb6cb62443 100644 (file)
@@ -301,7 +301,7 @@ m32c_info_to_howto_rela
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_M32C_max)
     {
-      _bfd_error_handler (_("%A: invalid M32C reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid M32C reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = & m32c_elf_howto_table [r_type];
index 51aff555191c8a666c6ba5d6b8b1b429244a8003..85949b147e92a5202a18dbb7e82f6d355bfdd9ba 100644 (file)
@@ -1282,7 +1282,7 @@ m32r_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type > (unsigned int) R_M32R_GNU_VTENTRY)
     {
-      _bfd_error_handler (_("%A: invalid M32R reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid M32R reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &m32r_elf_howto_table[r_type];
index 7f70a1c1f79d53007840313ab5054332729a27e5..b7a728fe7500644958b5383dd2b031427b4baf32 100644 (file)
@@ -386,7 +386,7 @@ m68hc11_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_M68HC11_max)
     {
-      _bfd_error_handler (_("%A: invalid M68HC11 reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid M68HC11 reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &elf_m68hc11_howto_table[r_type];
index 1df3491c8eb46952bd95fa7aad3a0af4bbde6b21..74361d3306dd968bae889259d6107b8ed8ee04cf 100644 (file)
@@ -506,7 +506,7 @@ m68hc11_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_M68HC11_max)
     {
-      _bfd_error_handler (_("%A: invalid M68HC12 reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid M68HC12 reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &elf_m68hc11_howto_table[r_type];
index f8c5beb2de5b25314d4ce9cda908980efd2a7147..2e6a33b26ab12668e6245d581dd35733341adc57 100644 (file)
@@ -349,7 +349,7 @@ mcore_elf_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= R_MCORE_max)
     {
-      (*_bfd_error_handler) (_("%A: unrecognised MCore reloc number: %d"),
+      (*_bfd_error_handler) (_("%B: unrecognised MCore reloc number: %d"),
                             abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
       r_type = R_MCORE_NONE;
index d94c13c2ce7ced23b26d9f5e5be566cca4abbc63..4032d2a6777a63e27f771cf2e2965b243750da4c 100644 (file)
@@ -402,7 +402,7 @@ mep_info_to_howto_rela
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= R_MEP_max)
     {
-      _bfd_error_handler (_("%A: invalid MEP reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid MEP reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = & mep_elf_howto_table [r_type];
index 84c7623d90d152161bafa9fc832daf531c5af7bf..71147472d46ff497c689a5b2e74996e0afbe6d2d 100644 (file)
@@ -898,7 +898,7 @@ metag_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_METAG_MAX)
     {
-      _bfd_error_handler (_("%A: invalid METAG reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid METAG reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = & elf_metag_howto_table [r_type];
index 50dce2720b894c34c106210c9510cf1d06dddb6c..e84b1b966e6eb3dda3fdcabbba8cd60346b9a628 100644 (file)
@@ -652,7 +652,7 @@ microblaze_elf_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= R_MICROBLAZE_max)
     {
-      (*_bfd_error_handler) (_("%A: unrecognised MicroBlaze reloc number: %d"),
+      (*_bfd_error_handler) (_("%B: unrecognised MicroBlaze reloc number: %d"),
                             abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
       r_type = R_MICROBLAZE_NONE;
index 7123ac10411182d6710fec2551e5c9731718120d..6b4a5ab757dbdaa43429499f1705a4a3281cacc4 100644 (file)
@@ -133,7 +133,7 @@ moxie_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_MOXIE_max)
     {
-      _bfd_error_handler (_("%A: invalid Moxie reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid Moxie reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = & moxie_elf_howto_table [r_type];
index 921c5d38fc6afdf7fff0f3fe9a89b8f8a42452a4..c839ea0d1fc29ce0f4f712d6bca44333ac424dee 100644 (file)
@@ -619,7 +619,7 @@ msp430_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED,
     {
       if (r_type >= (unsigned int) R_MSP430x_max)
        {
-         _bfd_error_handler (_("%A: invalid MSP430X reloc number: %d"), abfd, r_type);
+         _bfd_error_handler (_("%B: invalid MSP430X reloc number: %d"), abfd, r_type);
          r_type = 0;
        }
       cache_ptr->howto = elf_msp430x_howto_table + r_type;
@@ -628,7 +628,7 @@ msp430_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED,
 
   if (r_type >= (unsigned int) R_MSP430_max)
     {
-      _bfd_error_handler (_("%A: invalid MSP430 reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid MSP430 reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &elf_msp430_howto_table[r_type];
index 6a4430fe9425f56954839c49f43af9c69e3c9721..7bfa18e0bd1a6e706adc494744ea0359ca56d36c 100644 (file)
@@ -238,7 +238,7 @@ mt_info_to_howto_rela
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_MT_max)
     {
-      _bfd_error_handler (_("%A: invalid MT reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid MT reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = & mt_elf_howto_table [r_type];
index 081b9976f1be433e399d962fa8b673b450aeae4b..ed4383db5a341dda1b604648668b5a6fa49c4e5d 100644 (file)
@@ -2968,7 +2968,7 @@ nds32_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type > R_NDS32_GNU_VTENTRY)
     {
-      _bfd_error_handler (_("%A: invalid NDS32 reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid NDS32 reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = bfd_elf32_bfd_reloc_type_table_lookup (r_type);
index fa2e9859bab31d195c8a929037865094a5f8cab3..efcefea45425d7f91a9c90ad1c7474a3f8f5d8a1 100644 (file)
@@ -740,7 +740,7 @@ or1k_info_to_howto_rela (bfd * abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_OR1K_max)
     {
-      _bfd_error_handler (_("%A: invalid OR1K reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid OR1K reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = & or1k_elf_howto_table[r_type];
index aa09e5683946d0e25a1913198b9430684b18f1cd..5a509f103ccb0104a9fc480db0fc14c2dbf0e689 100644 (file)
@@ -321,7 +321,7 @@ pj_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
 
   if (r >= R_PJ_max)
     {
-      (*_bfd_error_handler) (_("%A: unrecognised PicoJava reloc number: %d"),
+      (*_bfd_error_handler) (_("%B: unrecognised PicoJava reloc number: %d"),
                             abfd, r);
       bfd_set_error (bfd_error_bad_value);
       r = R_PJ_NONE;
index c467f14b6872d4519f87c59f5d6146fd1afba742..640ced978cbf98d9f390fa5c89735e8878a54828 100644 (file)
@@ -2028,7 +2028,7 @@ ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= R_PPC_max)
     {
-      (*_bfd_error_handler) (_("%A: unrecognised PPC reloc number: %d"),
+      (*_bfd_error_handler) (_("%B: unrecognised PPC reloc number: %d"),
                             abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
       r_type = R_PPC_NONE;
index 3230c8c059ad1d48bf9c5f892669a116ffd19ad7..1bb5edcac31f0286cae7369520f34a8c8c096dc2 100644 (file)
@@ -278,7 +278,7 @@ rl78_info_to_howto_rela (bfd *               abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_RL78_max)
     {
-      _bfd_error_handler (_("%A: invalid RL78 reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid RL78 reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = rl78_elf_howto_table + r_type;
index beb4e09d7c1297f135c862448d20bd48daec20d0..5d35d2aad6e45dfae3da83e94c8ce656b9bf3c60 100644 (file)
@@ -309,7 +309,7 @@ rx_info_to_howto_rela (bfd *               abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_RX_max)
     {
-      _bfd_error_handler (_("%A: invalid RX reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid RX reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = rx_elf_howto_table + r_type;
index f92cdff3e201d0350f59c6952a4583568ecffaea..567ef249f711a4b8e30110d382728ec8580c8cdd 100644 (file)
@@ -487,7 +487,7 @@ sh_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
       || (r >= R_SH_FIRST_INVALID_RELOC_5 && r <= R_SH_LAST_INVALID_RELOC_5)
       || (r >= R_SH_FIRST_INVALID_RELOC_6 && r <= R_SH_LAST_INVALID_RELOC_6))
     {
-      (*_bfd_error_handler) (_("%A: unrecognised SH reloc number: %d"),
+      (*_bfd_error_handler) (_("%B: unrecognised SH reloc number: %d"),
                             abfd, r);
       bfd_set_error (bfd_error_bad_value);
       r = R_SH_NONE;
index 82032864157180806d7127c8613ac6a3866e86da..4472b3aaa85df4199170b99b305981cbdca38ea3 100644 (file)
@@ -156,7 +156,7 @@ spu_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
   /* PR 17512: file: 90c2a92e.  */
   if (r_type >= R_SPU_max)
     {
-      (*_bfd_error_handler) (_("%A: unrecognised SPU reloc number: %d"),
+      (*_bfd_error_handler) (_("%B: unrecognised SPU reloc number: %d"),
                             abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
       r_type = R_SPU_NONE;
index 2d7337a3b44185b8bf03d93be252cddd93e77c97..0155b7d1a072b471e0a649c2797172ea1c8b6913 100644 (file)
@@ -494,7 +494,7 @@ v850_elf_perform_relocation (bfd *abfd,
     {
     default:
 #ifdef DEBUG
-      fprintf (stderr, "reloc number %d not recognised\n", r_type);
+      fprintf (stderr, "%B: reloc number %d not recognised\n", abfd, r_type);
 #endif
       return bfd_reloc_notsupported;
 
@@ -1898,7 +1898,7 @@ v850_elf_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_V850_max)
     {
-      _bfd_error_handler (_("%A: invalid V850 reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid V850 reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &v850_elf_howto_table[r_type];
@@ -1916,7 +1916,7 @@ v850_elf_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_V850_max)
     {
-      _bfd_error_handler (_("%A: invalid V850 reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid V850 reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &v850_elf_howto_table[r_type];
@@ -2147,7 +2147,7 @@ v850_elf_final_link_relocate (reloc_howto_type *howto,
 
     default:
 #ifdef DEBUG
-      fprintf (stderr, "reloc number %d not recognised\n", r_type);
+      fprintf (stderr, "%B: reloc number %d not recognised\n", input_bfd, r_type);
 #endif
       return bfd_reloc_notsupported;
     }
index 8ed7215752e69bb8a9c0eeee84821bd0ba50dba4..85fe5f49534be2438cbeb72844820e69e8937dd3 100644 (file)
@@ -280,15 +280,14 @@ static reloc_howto_type howto_table[] = {
 };
 
 static void
-rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
-               Elf_Internal_Rela *dst)
+rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
 {
   unsigned int r_type;
 
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= R_VAX_max)
     {
-      (*_bfd_error_handler) (_("%A: unrecognised VAX reloc number: %d"),
+      (*_bfd_error_handler) (_("%B: unrecognised VAX reloc number: %d"),
                             abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
       r_type = R_VAX_NONE;
index 3344a42eb0a4ef953d67747bae23f00b44e0df75..d6256f6301451480d3c95b32cd020238b13cc1a3 100644 (file)
@@ -503,7 +503,7 @@ visium_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
     default:
       if (r_type >= (unsigned int) R_VISIUM_max)
        {
-         _bfd_error_handler (_("%A: invalid Visium reloc number: %d"), abfd, r_type);
+         _bfd_error_handler (_("%B: invalid Visium reloc number: %d"), abfd, r_type);
          r_type = 0;
        }
       cache_ptr->howto = &visium_elf_howto_table[r_type];
index 555e83e2b31681caae8cfb3567ba1ef752804a70..4c416b3010daf17028f5529d285413163ae80ce7 100644 (file)
@@ -424,7 +424,7 @@ xgate_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF32_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_XGATE_max)
     {
-      _bfd_error_handler (_("%A: invalid XGate reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid XGate reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &elf_xgate_howto_table[r_type];
index f7c07a84453a8368a0c70b17d996cd301d0bfa12..0b6f584d6e36bf5ab7bb1ebad9cf99b63cd82453 100644 (file)
@@ -481,7 +481,7 @@ elf_xtensa_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
 
   if (r_type >= (unsigned int) R_XTENSA_max)
     {
-      _bfd_error_handler (_("%A: invalid XTENSA reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid XTENSA reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &elf_howto_table[r_type];
index 680c0ec5ac2832b79253172333dea66393e2f118..cfd328a229e0ccb482a083e94cf5c9c837c0d26d 100644 (file)
@@ -1108,7 +1108,7 @@ elf64_alpha_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
 
   if (r_type >= R_ALPHA_max)
     {
-      (*_bfd_error_handler) (_("%A: unrecognised Alpha reloc number: %d"),
+      (*_bfd_error_handler) (_("%B: unrecognised Alpha reloc number: %d"),
                             abfd, r_type);
       bfd_set_error (bfd_error_bad_value);
       r_type = R_ALPHA_NONE;
index 845acd7de601188d72cd25c00e28c17c7177fb96..38d07b3cad8f1ed8d921d4a0dd358ab8034b5329 100644 (file)
@@ -1261,7 +1261,7 @@ mmix_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
   r_type = ELF64_R_TYPE (dst->r_info);
   if (r_type >= (unsigned int) R_MMIX_max)
     {
-      _bfd_error_handler (_("%A: invalid MMIX reloc number: %d"), abfd, r_type);
+      _bfd_error_handler (_("%B: invalid MMIX reloc number: %d"), abfd, r_type);
       r_type = 0;
     }
   cache_ptr->howto = &elf_mmix_howto_table[r_type];
index e136c2d3994052c9b2621e8bebd661bce29072a3..d44b94c7ed56288bd12f13ff62d18f0b535cfeae 100644 (file)
@@ -390,7 +390,7 @@ bfd_mach_o_convert_section_name_to_bfd (bfd *abfd, const char *segname,
   if (xlat)
     {
       len = strlen (xlat->bfd_name);
-      res = bfd_alloc (abfd, len+1);
+      res = bfd_alloc (abfd, len + 1);
       if (res == NULL)
        return;
       memcpy (res, xlat->bfd_name, len+1);
@@ -1389,7 +1389,7 @@ bfd_mach_o_canonicalize_one_reloc (bfd *abfd,
       if (reloc.r_extern)
        {
          /* PR 17512: file: 8396-1185-0.004.  */
-         if (bfd_get_symcount (abfd) > 0 && num > bfd_get_symcount (abfd))
+         if (num >= bfd_mach_o_count_symbols (abfd))
            sym = bfd_und_section_ptr->symbol_ptr_ptr;
          else if (syms == NULL)
            sym = bfd_und_section_ptr->symbol_ptr_ptr;      
@@ -1457,6 +1457,10 @@ bfd_mach_o_canonicalize_relocs (bfd *abfd, unsigned long filepos,
   /* Allocate and read relocs.  */
   native_size = count * BFD_MACH_O_RELENT_SIZE;
 
+  /* PR 17512: file: 09477b57.  */
+  if (native_size < count)
+    return -1;
+
   native_relocs =
     (struct mach_o_reloc_info_external *) bfd_malloc (native_size);
   if (native_relocs == NULL)
@@ -1496,6 +1500,8 @@ bfd_mach_o_canonicalize_reloc (bfd *abfd, asection *asect,
 
   if (asect->relocation == NULL)
     {
+      if (asect->reloc_count * sizeof (arelent) < asect->reloc_count)
+       return -1;
       res = bfd_malloc (asect->reloc_count * sizeof (arelent));
       if (res == NULL)
         return -1;
@@ -1549,6 +1555,10 @@ bfd_mach_o_canonicalize_dynamic_reloc (bfd *abfd, arelent **rels,
 
   if (mdata->dyn_reloc_cache == NULL)
     {
+      if ((dysymtab->nextrel + dysymtab->nlocrel) * sizeof (arelent)
+         < (dysymtab->nextrel + dysymtab->nlocrel))
+       return -1;
+
       res = bfd_malloc ((dysymtab->nextrel + dysymtab->nlocrel)
                         * sizeof (arelent));
       if (res == NULL)
@@ -1863,11 +1873,10 @@ bfd_mach_o_write_symtab_content (bfd *abfd, bfd_mach_o_symtab_command *sym)
   mdata->filelen += sym->strsize;
 
   if (bfd_seek (abfd, sym->stroff, SEEK_SET) != 0)
-    return FALSE;
+    goto err;
 
   if (_bfd_stringtab_emit (abfd, strtab) != TRUE)
     goto err;
-  _bfd_stringtab_free (strtab);
 
   /* Pad string table.  */
   padlen = bfd_mach_o_pad4 (abfd, sym->strsize);
@@ -1880,6 +1889,7 @@ bfd_mach_o_write_symtab_content (bfd *abfd, bfd_mach_o_symtab_command *sym)
 
  err:
   _bfd_stringtab_free (strtab);
+  sym->strsize = 0;
   return FALSE;
 }
 
@@ -1997,6 +2007,8 @@ bfd_mach_o_build_dysymtab (bfd *abfd, bfd_mach_o_dysymtab_command *cmd)
       cmd->indirectsymoff = mdata->filelen;
       mdata->filelen += cmd->nindirectsyms * 4;
 
+      if (cmd->nindirectsyms * 4 < cmd->nindirectsyms)
+       return FALSE;
       cmd->indirect_syms = bfd_zalloc (abfd, cmd->nindirectsyms * 4);
       if (cmd->indirect_syms == NULL)
         return FALSE;
@@ -2392,8 +2404,8 @@ bfd_mach_o_mangle_sections (bfd *abfd, bfd_mach_o_data_struct *mdata)
     }
 
   mdata->nsects = nsect;
-  mdata->sections = bfd_alloc (abfd,
-                              mdata->nsects * sizeof (bfd_mach_o_section *));
+  mdata->sections = bfd_alloc2 (abfd,
+                               mdata->nsects, sizeof (bfd_mach_o_section *));
   if (mdata->sections == NULL)
     return FALSE;
 
@@ -3731,32 +3743,28 @@ bfd_mach_o_read_symtab_symbols (bfd *abfd)
     /* Return now if there are no symbols or if already loaded.  */
     return TRUE;
 
-  sym->symbols = bfd_alloc (abfd, sym->nsyms * sizeof (bfd_mach_o_asymbol));
-
+  sym->symbols = bfd_alloc2 (abfd, sym->nsyms, sizeof (bfd_mach_o_asymbol));
   if (sym->symbols == NULL)
     {
       (*_bfd_error_handler) (_("bfd_mach_o_read_symtab_symbols: unable to allocate memory for symbols"));
+      sym->nsyms = 0;
       return FALSE;
     }
 
   if (!bfd_mach_o_read_symtab_strtab (abfd))
-    {
-      bfd_release (abfd, sym->symbols);
-      sym->symbols = NULL;
-      return FALSE;
-    }
+    goto fail;
 
   for (i = 0; i < sym->nsyms; i++)
-    {
-      if (!bfd_mach_o_read_symtab_symbol (abfd, sym, &sym->symbols[i], i))
-       {
-         bfd_release (abfd, sym->symbols);
-         sym->symbols = NULL;
-         return FALSE;
-       }
-    }
+    if (!bfd_mach_o_read_symtab_symbol (abfd, sym, &sym->symbols[i], i))
+      goto fail;
 
   return TRUE;
+
+ fail:
+  bfd_release (abfd, sym->symbols);
+  sym->symbols = NULL;
+  sym->nsyms = 0;
+  return FALSE;
 }
 
 static const char *
@@ -3989,8 +3997,8 @@ bfd_mach_o_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
     }
 
   /* Allocate threads.  */
-  cmd->flavours = bfd_alloc
-    (abfd, nflavours * sizeof (bfd_mach_o_thread_flavour));
+  cmd->flavours = bfd_alloc2
+    (abfd, nflavours, sizeof (bfd_mach_o_thread_flavour));
   if (cmd->flavours == NULL)
     return FALSE;
   cmd->nflavours = nflavours;
@@ -4113,7 +4121,7 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
       unsigned int module_len = wide ? 56 : 52;
 
       cmd->dylib_module =
-        bfd_alloc (abfd, cmd->nmodtab * sizeof (bfd_mach_o_dylib_module));
+        bfd_alloc2 (abfd, cmd->nmodtab, sizeof (bfd_mach_o_dylib_module));
       if (cmd->dylib_module == NULL)
         return FALSE;
 
@@ -4159,10 +4167,10 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
 
   if (cmd->ntoc != 0)
     {
-      unsigned int i;
+      unsigned long i;
 
-      cmd->dylib_toc = bfd_alloc
-        (abfd, cmd->ntoc * sizeof (bfd_mach_o_dylib_table_of_content));
+      cmd->dylib_toc = bfd_alloc2
+        (abfd, cmd->ntoc, sizeof (bfd_mach_o_dylib_table_of_content));
       if (cmd->dylib_toc == NULL)
         return FALSE;
 
@@ -4186,8 +4194,8 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
     {
       unsigned int i;
 
-      cmd->indirect_syms = bfd_alloc
-        (abfd, cmd->nindirectsyms * sizeof (unsigned int));
+      cmd->indirect_syms = bfd_alloc2
+        (abfd, cmd->nindirectsyms, sizeof (unsigned int));
       if (cmd->indirect_syms == NULL)
         return FALSE;
 
@@ -4211,8 +4219,8 @@ bfd_mach_o_read_dysymtab (bfd *abfd, bfd_mach_o_load_command *command)
       unsigned long v;
       unsigned int i;
 
-      cmd->ext_refs = bfd_alloc
-        (abfd, cmd->nextrefsyms * sizeof (bfd_mach_o_dylib_reference));
+      cmd->ext_refs = bfd_alloc2
+        (abfd, cmd->nextrefsyms, sizeof (bfd_mach_o_dylib_reference));
       if (cmd->ext_refs == NULL)
         return FALSE;
 
@@ -4743,8 +4751,8 @@ bfd_mach_o_flatten_sections (bfd *abfd)
     }
 
   /* Allocate sections array.  */
-  mdata->sections = bfd_alloc (abfd,
-                              mdata->nsects * sizeof (bfd_mach_o_section *));
+  mdata->sections = bfd_alloc2 (abfd,
+                               mdata->nsects, sizeof (bfd_mach_o_section *));
 
   /* Fill the array.  */
   csect = 0;
@@ -4916,7 +4924,8 @@ bfd_mach_o_scan (bfd *abfd,
 
       mdata->first_command = NULL;
       mdata->last_command = NULL;
-      cmd = bfd_alloc (abfd, header->ncmds * sizeof (bfd_mach_o_load_command));
+
+      cmd = bfd_alloc2 (abfd, header->ncmds, sizeof (bfd_mach_o_load_command));
       if (cmd == NULL)
        return FALSE;
 
@@ -5152,7 +5161,7 @@ bfd_mach_o_archive_p (bfd *abfd)
     goto error;
 
   adata->archentries =
-    bfd_alloc (abfd, adata->nfat_arch * sizeof (mach_o_fat_archentry));
+    bfd_alloc2 (abfd, adata->nfat_arch, sizeof (mach_o_fat_archentry));
   if (adata->archentries == NULL)
     goto error;
 
@@ -5169,6 +5178,7 @@ bfd_mach_o_archive_p (bfd *abfd)
     }
 
   abfd->tdata.mach_o_fat_data = adata;
+
   return abfd->xvec;
 
  error:
index 122ddf125643e1a66bfd1d396a8110791540bc97..45f1937e9b415ce38444b6dd0f11205379125ad0 100644 (file)
@@ -1757,6 +1757,8 @@ pe_print_edata (bfd * abfd, void * vfile)
 
   /* PR 17512: Handle corrupt PE binaries.  */
   if (edt.eat_addr + (edt.num_functions * 4) - adj >= datasize
+      /* PR 17512: file: 092b1829 */
+      || (edt.num_functions * 4) < edt.num_functions
       /* PR 17512 file: 140-165018-0.004.  */
       || data + edt.eat_addr - adj < data)
     fprintf (file, _("\tInvalid Export Address Table rva (0x%lx) or entry count (0x%lx)\n"),
@@ -1801,6 +1803,8 @@ pe_print_edata (bfd * abfd, void * vfile)
 
   /* PR 17512: Handle corrupt PE binaries.  */
   if (edt.npt_addr + (edt.num_names * 4) - adj >= datasize
+      /* PR 17512: file: bb68816e.  */
+      || edt.num_names * 4 < edt.num_names
       || (data + edt.npt_addr - adj) < data)
     fprintf (file, _("\tInvalid Name Pointer Table rva (0x%lx) or entry count (0x%lx)\n"),
             (long) edt.npt_addr,
index 63d7d8de5e073d1a752d24330163618cf928e672..ccc68f92d397306fe0a38f827af77d4f33a6b0fc 100644 (file)
@@ -397,7 +397,7 @@ first_phase (bfd *abfd, int type, char *src, char * src_end)
            return FALSE;
        }
       alt_section = NULL;
-      while (*src)
+      while (src < src_end && *src)
        {
          switch (*src)
            {
index 37754e75a4e1a8dcd95f1f17ad9f56f66e379ae9..4a6de8d18b8cb25a9c994fb5d5cc167fe4f17057 100644 (file)
@@ -1,3 +1,8 @@
+2015-02-03  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/17512
+       * objdump.c (display_any_bfd): Fail if archives nest too deeply.
+
 2015-01-28  James Bowman  <james.bowman@ftdichip.com>
 
        * readelf.c: Add FT32 support.
index 54fc235a5ae4381819e366b5981f62e659fb9791..98e4d86f69b4377314cce77ba304b20b5e6f9da3 100644 (file)
@@ -3413,7 +3413,7 @@ display_any_bfd (bfd *file, int level)
        {
          /* Prevent corrupted files from spinning us into an
             infinite loop.  100 is an arbitrary heuristic.  */
-         non_fatal (_("Archive nesting is too deep"));
+         fatal (_("Archive nesting is too deep"));
          return;
        }
       else