From 54025d5812ff100f5f0654eb7e1ffd50f2e37f5f Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Mon, 31 Dec 2018 15:40:08 +1030 Subject: [PATCH] PR24041, Invalid Memory Address Dereference in elf_link_add_object_symbols PR 24041 * elflink.c (elf_link_add_object_symbols): Don't segfault on crafted ET_DYN with no program headers. --- diff -urNp a/bfd/ChangeLog b/bfd/ChangeLog --- a/bfd/ChangeLog 2019-06-06 00:21:45.780000000 +0800 +++ b/bfd/ChangeLog 2019-06-06 00:23:26.300000000 +0800 @@ -1,3 +1,8 @@ +2018-12-31 Alan Modra + PR 24041 + * elflink.c (elf_link_add_object_symbols): Don't segfault on + crafted ET_DYN with no program headers. + 2018-09-20 Alan Modra PR 23685 * peXXigen.c (pe_print_edata): Correct export address table diff -urNp a/bfd/elflink.c b/bfd/elflink.c --- a/bfd/elflink.c 2019-06-06 00:21:45.770000000 +0800 +++ b/bfd/elflink.c 2019-06-06 00:24:50.330000000 +0800 @@ -4169,7 +4169,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)