Fix use-after-free error when parsing a corrupt nested archive.
authorNick Clifton <nickc@redhat.com>
Wed, 19 Jul 2017 13:49:12 +0000 (14:49 +0100)
committerNick Clifton <nickc@redhat.com>
Wed, 19 Jul 2017 13:49:12 +0000 (14:49 +0100)
PR 21787
* archive.c (bfd_generic_archive_p): If the bfd does not have the
correct magic bytes at the start, set the error to wrong format
and clear the format selector before returning NULL.

bfd/ChangeLog
bfd/archive.c

index b883758..cc7f45c 100644 (file)
@@ -1,5 +1,12 @@
 2017-07-19  Nick Clifton  <nickc@redhat.com>
 
+       PR 21787
+       * archive.c (bfd_generic_archive_p): If the bfd does not have the
+       correct magic bytes at the start, set the error to wrong format
+       and clear the format selector before returning NULL.
+
+2017-07-19  Nick Clifton  <nickc@redhat.com>
+
        PR 21786
        * coff-rs6000.c (_bfd_strntol): New function.
        (_bfd_strntoll): New function.
index f209bab..885bf48 100644 (file)
@@ -834,7 +834,12 @@ bfd_generic_archive_p (bfd *abfd)
   if (strncmp (armag, ARMAG, SARMAG) != 0
       && strncmp (armag, ARMAGB, SARMAG) != 0
       && ! bfd_is_thin_archive (abfd))
-    return NULL;
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      if (abfd->format == bfd_archive)
+       abfd->format = bfd_unknown;
+      return NULL;
+    }
 
   tdata_hold = bfd_ardata (abfd);