This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb/binutils-2_29-branch] Import patch from mainline to improve reporting of corrupt archives.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a541116faa5716d5c1a4bc9d1567855902b89a87

commit a541116faa5716d5c1a4bc9d1567855902b89a87
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Sep 4 16:14:19 2017 +0100

    Import patch from mainline to improve reporting of corrupt archives.
    
    	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.

Diff:
---
 bfd/ChangeLog | 5 +++++
 bfd/archive.c | 7 ++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 1bba945..7be3d82 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -21,6 +21,11 @@
 	(GET_VALUE_IN_FIELD): New macro.
 	(xcoff64_slurp_armap): Use new macros.
 
+	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-09-04  Alan Modra  <amodra@gmail.com>
 
 	PR 22067
diff --git a/bfd/archive.c b/bfd/archive.c
index f209bab..885bf48 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -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);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]