PATCH: Check bad symbol index in ia64 reloc

H. J. Lu hjl@lucon.org
Tue Sep 23 19:49:00 GMT 2003


The ia64 linker may crash on bad symbol index in reloc for an invalid
input file. This patch checks it.


H.J.
-------------- next part --------------
2003-09-23  H.J. Lu  <hongjiu.lu@intel.com>

	* elfxx-ia64.c (elfNN_ia64_check_relocs): Check bad symbol
	index.

--- bfd/elfxx-ia64.c.bad	2003-09-23 11:33:45.000000000 -0700
+++ bfd/elfxx-ia64.c	2003-09-23 12:45:13.000000000 -0700
@@ -2124,6 +2124,7 @@ elfNN_ia64_check_relocs (abfd, info, sec
   Elf_Internal_Shdr *symtab_hdr;
   const Elf_Internal_Rela *rel;
   asection *got, *fptr, *srel;
+  size_t nsyms;
 
   if (info->relocatable)
     return TRUE;
@@ -2131,6 +2132,8 @@ elfNN_ia64_check_relocs (abfd, info, sec
   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   ia64_info = elfNN_ia64_hash_table (info);
 
+  nsyms = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
+
   got = fptr = srel = NULL;
 
   relend = relocs + sec->reloc_count;
@@ -2157,6 +2160,16 @@ elfNN_ia64_check_relocs (abfd, info, sec
       bfd_boolean maybe_dynamic;
       int dynrel_type = R_IA64_NONE;
 
+      if (r_symndx >= nsyms)
+	{
+	  (*info->callbacks->error_handler)
+	    (0, _("%P: bad reloc symbol index (0x%v >= 0x%v) for offset 0x%v in section `%s' in `%B'\n"),
+	     (bfd_vma) r_symndx, (bfd_vma) nsyms,
+	     rel->r_offset, sec->name, abfd);
+	  bfd_set_error (bfd_error_bad_value);
+	  return FALSE;
+	}
+
       if (r_symndx >= symtab_hdr->sh_info)
 	{
 	  /* We're dealing with a global symbol -- find its hash entry


More information about the Binutils mailing list