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]

Re: PR5900


On Wed, Mar 12, 2008 at 3:21 PM, Alan Modra <amodra@bigpond.net.au> wrote:
> On Wed, Mar 12, 2008 at 02:13:02PM -0700, H.J. Lu wrote:
>  >       * elf.c (assign_section_numbers): Check if number of sections
>  >       >= SHN_LORESERVE.
>
>  Hmm, ld will have attempted to use at least 5 terabytes of memory
>  before we hit this error.  Do you really think it is worth adding this
>  check?
>
>  >       * elfcode.h (elf_object_p): Likewise.
>
>  Error messages are not appropriate for got_wrong_format_error where
>  you might try multiple targets and get the same error multiple times.
>

I don't think we will hit this limit. But you never know how people will use it.
Here is an updated patch using abort () in elf_object_p.

H.J.
2008-03-12  H.J. Lu  <hongjiu.lu@intel.com>

	* elf.c (assign_section_numbers): Check if number of sections
	>= SHN_LORESERVE.
	* elfcode.h (elf_object_p): Likewise.

--- bfd/elf.c.64k	2008-03-12 12:32:53.000000000 -0700
+++ bfd/elf.c	2008-03-12 14:06:17.000000000 -0700
@@ -2831,6 +2831,13 @@ assign_section_numbers (bfd *abfd, struc
       _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->strtab_hdr.sh_name);
     }
 
+  if (section_number >= SHN_LORESERVE)
+    {
+      _bfd_error_handler (_("%B: too many sections: %u"),
+			  abfd, section_number);
+      return FALSE;
+    }
+
   _bfd_elf_strtab_finalize (elf_shstrtab (abfd));
   t->shstrtab_hdr.sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd));
 
--- bfd/elfcode.h.64k	2008-03-12 12:32:05.000000000 -0700
+++ bfd/elfcode.h	2008-03-12 15:30:51.000000000 -0700
@@ -684,8 +684,14 @@ elf_object_p (bfd *abfd)
       if (i_ehdrp->e_shnum == SHN_UNDEF)
 	{
 	  i_ehdrp->e_shnum = i_shdr.sh_size;
-	  if (i_ehdrp->e_shnum != i_shdr.sh_size
-	      || i_ehdrp->e_shnum == 0)
+	  if (i_ehdrp->e_shnum >= SHN_LORESERVE)
+	    {
+	      _bfd_error_handler (_("%B: too many sections: %u"),
+				  abfd, i_ehdrp->e_shnum);
+	      abort ();
+	    }
+	  else if (i_ehdrp->e_shnum != i_shdr.sh_size
+		   || i_ehdrp->e_shnum  == 0)
 	    goto got_wrong_format_error;
 	}
 

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