PR24041, Invalid Memory Address Dereference in elf_link_add_object_symbols

Message ID 20181231052710.GX30978@bubble.grove.modra.org
State New
Headers show
Series
  • PR24041, Invalid Memory Address Dereference in elf_link_add_object_symbols
Related show

Commit Message

Alan Modra Dec. 31, 2018, 5:27 a.m.
PR 24041
	* elflink.c (elf_link_add_object_symbols): Don't segfault on
	crafted ET_DYN with no program headers.


-- 
Alan Modra
Australia Development Lab, IBM

Patch

diff --git a/bfd/elflink.c b/bfd/elflink.c
index f5b411bd62..6e421fb6cd 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -4186,7 +4186,7 @@  error_free_dyn:
 	 all sections contained fully therein.  This makes relro
 	 shared library sections appear as they will at run-time.  */
       phdr = elf_tdata (abfd)->phdr + elf_elfheader (abfd)->e_phnum;
-      while (--phdr >= elf_tdata (abfd)->phdr)
+      while (phdr-- > elf_tdata (abfd)->phdr)
 	if (phdr->p_type == PT_GNU_RELRO)
 	  {
 	    for (s = abfd->sections; s != NULL; s = s->next)