This is the mail archive of the binutils@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]

PATCH: PR binutils/15151: archive support is broken


Hi,

I checked in this patch to fix archive support by disallowing a nested
archive pointing to itself, instead of caching the file position.


H.J.
---
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/bfd/ChangeLog,v
retrieving revision 1.5967
diff -u -p -r1.5967 ChangeLog
--- ChangeLog	15 Feb 2013 14:37:36 -0000	1.5967
+++ ChangeLog	15 Feb 2013 18:25:29 -0000
@@ -1,3 +1,10 @@
+2013-02-15  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR binutils/15151
+	* archive.c (_bfd_find_nested_archive): Don't allow a nested
+	archive pointing to itself.
+	(_bfd_get_elt_at_filepos): Revert the last 2 changes.
+
 2013-02-15  Nick Clifton  <nickc@redhat.com>
 
 	PR binutils/15140
Index: archive.c
===================================================================
RCS file: /cvs/src/src/bfd/archive.c,v
retrieving revision 1.97
diff -u -p -r1.97 archive.c
--- archive.c	15 Feb 2013 15:53:42 -0000	1.97
+++ archive.c	15 Feb 2013 18:25:30 -0000
@@ -379,6 +379,13 @@ _bfd_find_nested_archive (bfd *arch_bfd,
   bfd *abfd;
   const char *target;
 
+  /* PR 15140: Don't allow a nested archive pointing to itself.  */
+  if (filename_cmp (filename, arch_bfd->filename) == 0)
+    {
+      bfd_set_error (bfd_error_malformed_archive);
+      return NULL;
+    }
+
   for (abfd = arch_bfd->nested_archives;
        abfd != NULL;
        abfd = abfd->archive_next)
@@ -617,8 +624,6 @@ _bfd_append_relative_path (bfd *arch, ch
 bfd *
 _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos)
 {
-  static file_ptr prev_filepos;
-  static unsigned int dup_filepos_count = 0;
   struct areltdata *new_areldata;
   bfd *n_nfd;
   char *filename;
@@ -626,17 +631,6 @@ _bfd_get_elt_at_filepos (bfd *archive, f
   n_nfd = _bfd_look_for_bfd_in_cache (archive, filepos);
   if (n_nfd)
     return n_nfd;
-  /* PR15140: Prevent an infinite recursion scanning a malformed nested archive.  */
-  if (filepos == prev_filepos)
-    {
-      if (++ dup_filepos_count > 100)
-	{
-	  bfd_set_error (bfd_error_malformed_archive);
-	  return NULL;
-	}
-    }
-  else
-    dup_filepos_count = 0;
 
   if (0 > bfd_seek (archive, filepos, SEEK_SET))
     return NULL;
@@ -645,7 +639,6 @@ _bfd_get_elt_at_filepos (bfd *archive, f
     return NULL;
 
   filename = new_areldata->filename;
-  prev_filepos = filepos;
 
   if (bfd_is_thin_archive (archive))
     {


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