This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: RFA: Stop objdump crash on corrupt reloc table
On Wed, Sep 18, 2002 at 11:20:11AM +0930, Alan Modra wrote:
> On Tue, Sep 17, 2002 at 12:39:03PM -0400, Daniel Jacobowitz wrote:
> > 2002-09-17 Daniel Jacobowitz <drow@mvista.com>
> >
> > * elfcode.h (elf_slurp_reloc_table_from_section): Add nsyms
> > argument. Check for overflow.
> > (elf_slurp_reloc_table): Count symbols and pass nsyms to
> > elf_slurp_reloc_table_from_section.
>
> Looks OK, except..
>
> > @@ -1510,17 +1519,22 @@ elf_slurp_reloc_table (abfd, asect, symb
> > if (relents == NULL)
> > return false;
> >
> > + /* ``symbols'' is NULL-terminated. */
> > + nsyms = 0;
> > + while (symbols[nsyms] != NULL)
> > + nsyms++;
>
> bfd_get_symcount (abfd) ?
It isn't set. bfd_get_symcount() refers to the number of symbols in
the normal symtab, not the dynamic symtab. If it were anywhere even
remotely performance-critical, I'd add bfd_get_dynamic_symcount...
actually, I could do that anyway, it's quite easy. How's this look?
[BTW, I regenerated bfd-in2.h and:
-#define bfd_mach_v850ea 'A'
went away. It should have gone away some weeks ago so I'm not
fretting.]
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer
2002-09-17 Daniel Jacobowitz <drow@mvista.com>
* bfd-in.h (bfd_get_dynamic_symcount): Define.
* bfd.c (struct _bfd): Add dynsymcount.
* bfd-in2.h: Regenerated.
* elf.c (_bfd_elf_canonicalize_dynamic_symtab): Set
abfd->dynsymcount.
* elfcode.h (elf_slurp_reloc_table_from_section): Check
for overflow.
Index: bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.50
diff -u -p -r1.50 bfd-in.h
--- bfd-in.h 30 Aug 2002 18:36:18 -0000 1.50
+++ bfd-in.h 18 Sep 2002 02:09:41 -0000
@@ -529,6 +529,8 @@ extern void warn_deprecated
#define bfd_get_outsymbols(abfd) ((abfd)->outsymbols)
#define bfd_count_sections(abfd) ((abfd)->section_count)
+#define bfd_get_dynamic_symcount(abfd) ((abfd)->dynsymcount)
+
#define bfd_get_symbol_leading_char(abfd) ((abfd)->xvec->symbol_leading_char)
#define bfd_set_cacheable(abfd,bool) (((abfd)->cacheable = (boolean) (bool)), true)
Index: bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.169
diff -u -p -r1.169 bfd-in2.h
--- bfd-in2.h 30 Aug 2002 18:36:18 -0000 1.169
+++ bfd-in2.h 18 Sep 2002 02:09:42 -0000
@@ -535,6 +535,8 @@ extern void warn_deprecated
#define bfd_get_outsymbols(abfd) ((abfd)->outsymbols)
#define bfd_count_sections(abfd) ((abfd)->section_count)
+#define bfd_get_dynamic_symcount(abfd) ((abfd)->dynsymcount)
+
#define bfd_get_symbol_leading_char(abfd) ((abfd)->xvec->symbol_leading_char)
#define bfd_set_cacheable(abfd,bool) (((abfd)->cacheable = (boolean) (bool)), true)
@@ -1629,7 +1631,6 @@ enum bfd_architecture
bfd_arch_v850, /* NEC V850 */
#define bfd_mach_v850 0
#define bfd_mach_v850e 'E'
-#define bfd_mach_v850ea 'A'
bfd_arch_arc, /* ARC Cores */
#define bfd_mach_arc_5 0
#define bfd_mach_arc_6 1
@@ -3461,6 +3462,9 @@ struct _bfd
/* Symbol table for output BFD (with symcount entries). */
struct symbol_cache_entry **outsymbols;
+
+ /* Used for slurped dynamic symbol tables. */
+ unsigned int dynsymcount;
/* Pointer to structure which contains architecture information. */
const struct bfd_arch_info *arch_info;
Index: bfd.c
===================================================================
RCS file: /cvs/src/src/bfd/bfd.c,v
retrieving revision 1.36
diff -u -p -r1.36 bfd.c
--- bfd.c 31 Jul 2002 09:38:03 -0000 1.36
+++ bfd.c 18 Sep 2002 02:09:42 -0000
@@ -128,6 +128,9 @@ CODE_FRAGMENT
. {* Symbol table for output BFD (with symcount entries). *}
. struct symbol_cache_entry **outsymbols;
.
+. {* Used for slurped dynamic symbol tables. *}
+. unsigned int dynsymcount;
+.
. {* Pointer to structure which contains architecture information. *}
. const struct bfd_arch_info *arch_info;
.
Index: elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.161
diff -u -p -r1.161 elf.c
--- elf.c 11 Sep 2002 14:30:53 -0000 1.161
+++ elf.c 18 Sep 2002 02:09:43 -0000
@@ -5572,7 +5572,11 @@ _bfd_elf_canonicalize_dynamic_symtab (ab
asymbol **alocation;
{
struct elf_backend_data *bed = get_elf_backend_data (abfd);
- return bed->s->slurp_symbol_table (abfd, alocation, true);
+ long symcount = bed->s->slurp_symbol_table (abfd, alocation, true);
+
+ if (symcount >= 0)
+ bfd_get_dynamic_symcount (abfd) = symcount;
+ return symcount;
}
/* Return the size required for the dynamic reloc entries. Any
Index: elfcode.h
===================================================================
RCS file: /cvs/src/src/bfd/elfcode.h,v
retrieving revision 1.33
diff -u -p -r1.33 elfcode.h
--- elfcode.h 7 Jul 2002 09:10:39 -0000 1.33
+++ elfcode.h 18 Sep 2002 02:09:44 -0000
@@ -1421,6 +1421,13 @@ elf_slurp_reloc_table_from_section (abfd
if (ELF_R_SYM (rela.r_info) == 0)
relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
+ else if (ELF_R_SYM (rela.r_info) > bfd_get_dynamic_symcount (abfd))
+ {
+ (*_bfd_error_handler)
+ (_("%s(%s): relocation %d has invalid symbol index %ld"),
+ abfd->filename, asect->name, i, ELF_R_SYM (rela.r_info));
+ relent->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
+ }
else
{
asymbol **ps, *s;