x86: Check valid PLT sections before checking dynamic relocations
[deliverable/binutils-gdb.git] / bfd / elf32-i386.c
index 05ba2c3b15b9ce61dd70c4c8ddb18f482706240d..31ef02a568e8292971d2c462b0f9602717cb24f2 100644 (file)
@@ -6326,16 +6326,6 @@ elf_i386_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);
-
   non_lazy_plt = NULL;
   /* Silence GCC 6.  */
   lazy_plt = NULL;
@@ -6447,7 +6437,10 @@ elf_i386_get_synthetic_symtab (bfd *abfd,
        }
 
       if (plt_type == plt_unknown)
-       continue;
+       {
+         free (plt_contents);
+         continue;
+       }
 
       plts[j].sec = plt;
       plts[j].type = plt_type;
@@ -6487,6 +6480,16 @@ elf_i386_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.  */
This page took 0.02566 seconds and 4 git commands to generate.