summaryrefslogtreecommitdiff
path: root/bfd/elf64-x86-64.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-08-29 10:40:03 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-08-29 10:40:03 -0700
commit37c0b6ee65941d54fa8064c21b39f97fdc318156 (patch)
treeb11d475a03364db93860b3ea9a9a267af94fdbbd /bfd/elf64-x86-64.c
parent7ef3addbe195b6283d0baf59e081146dfb211c97 (diff)
x86: Check valid PLT sections before checking dynamic relocations
Update x86 get_synthetic_symtab to check valid PLT sections before checking dynamic relocations and free invalid PLT section contents. * elf32-i386.c (elf_i386_get_synthetic_symtab): Check valid PLT sections before checking dynamic relocations and free invalid PLT section contents. * elf64-x86-64.c (elf_x86_64_get_synthetic_symtab): Likewise.
Diffstat (limited to 'bfd/elf64-x86-64.c')
-rw-r--r--bfd/elf64-x86-64.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 25ce295c17..ba7c5953c3 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -6722,16 +6722,6 @@ elf_x86_64_get_synthetic_symtab (bfd *abfd,
if (relsize <= 0)
return -1;
- dynrelbuf = (arelent **) bfd_malloc (relsize);
- if (dynrelbuf == NULL)
- return -1;
-
- dynrelcount = bfd_canonicalize_dynamic_reloc (abfd, dynrelbuf,
- dynsyms);
-
- /* Sort the relocs by address. */
- qsort (dynrelbuf, dynrelcount, sizeof (arelent *), compare_relocs);
-
if (get_elf_x86_64_backend_data (abfd)->os == is_normal)
{
lazy_plt = &elf_x86_64_lazy_plt;
@@ -6842,7 +6832,10 @@ elf_x86_64_get_synthetic_symtab (bfd *abfd,
}
if (plt_type == plt_unknown)
- continue;
+ {
+ free (plt_contents);
+ continue;
+ }
plts[j].sec = plt;
plts[j].type = plt_type;
@@ -6879,6 +6872,16 @@ elf_x86_64_get_synthetic_symtab (bfd *abfd,
if (count == 0)
return -1;
+ dynrelbuf = (arelent **) bfd_malloc (relsize);
+ if (dynrelbuf == NULL)
+ return -1;
+
+ dynrelcount = bfd_canonicalize_dynamic_reloc (abfd, dynrelbuf,
+ dynsyms);
+
+ /* Sort the relocs by address. */
+ qsort (dynrelbuf, dynrelcount, sizeof (arelent *), compare_relocs);
+
size = count * sizeof (asymbol);
/* Allocate space for @plt suffixes. */