This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

invalid reloc sections


This reverts a patch Jakub made to prevent bfd crashes in
http://sources.redhat.com/ml/binutils/2005-06/msg00373.html, instead
avoiding crashes by treating invalid reloc sections as normal sections.
The point being that Jakub's patch prevents BFD from recognizing the
file as a valid ELF object, while this approach allows a user to do such
things as objcopy -R the offending reloc section.

	* elf.c (bfd_section_from_shdr): Treat invalid reloc sections as
	normal sections rather than returning false.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.321
diff -u -p -r1.321 elf.c
--- bfd/elf.c	13 Dec 2005 15:34:28 -0000	1.321
+++ bfd/elf.c	27 Dec 2005 03:31:26 -0000
@@ -2045,15 +2045,16 @@ bfd_section_from_shdr (bfd *abfd, unsign
 	   represent such a section, so at least for now, we don't
 	   try.  We just present it as a normal section.  We also
 	   can't use it as a reloc section if it points to the null
-	   section.  */
-	if (hdr->sh_link != elf_onesymtab (abfd) || hdr->sh_info == SHN_UNDEF)
+	   section, an invalid section, or another reloc section.  */
+	if (hdr->sh_link != elf_onesymtab (abfd)
+	    || hdr->sh_info == SHN_UNDEF
+	    || (hdr->sh_info >= SHN_LORESERVE && hdr->sh_info <= SHN_HIRESERVE)
+	    || hdr->sh_info >= num_sec
+	    || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_REL
+	    || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_RELA)
 	  return _bfd_elf_make_section_from_shdr (abfd, hdr, name,
 						  shindex);
 
-	/* Prevent endless recursion on broken objects.  */
-	if (elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_REL
-	    || elf_elfsections (abfd)[hdr->sh_info]->sh_type == SHT_RELA)
-	  return FALSE;
 	if (! bfd_section_from_shdr (abfd, hdr->sh_info))
 	  return FALSE;
 	target_sect = bfd_section_from_elf_index (abfd, hdr->sh_info);

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]