Bug 15151 - archive support is broken
Summary: archive support is broken
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.24
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-15 17:15 UTC by H.J. Lu
Modified: 2013-02-15 19:29 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2013-02-15 17:15:28 UTC
This patch:

http://sourceware.org/ml/binutils-cvs/2013-02/msg00118.html

breaks archive on x86-64:

[hjl@gnu-6 binutils]$ cat foo.s
	.text
	.global foo
foo:
	nop
[hjl@gnu-6 binutils]$ ../gas/as-new --x32 -o foo.o foo.s
[hjl@gnu-6 binutils]$ ./ar rc libfoo.a foo.o
[hjl@gnu-6 binutils]$ ./nm-new --print-armap libfoo.a
./nm-new: libfoo.a: File format not recognized
[hjl@gnu-6 binutils]$
Comment 1 Hans-Peter Nilsson 2013-02-15 17:18:36 UTC
Hey!  I was just about to email Nick about the fallout; cris-linux and cris-elf have the following regressions, which I believe fit in this PR:

Running /tmp/hpautotest-binutils/bsrc/src/binutils/testsuite/binutils-all/ar.exp ...
FAIL: ar symbol table
FAIL: ar thin archive (bfdtest1)
FAIL: ar thin archive with nested archive (bfdtest1)
FAIL: ar deterministic archive
FAIL: ar deleting an element
FAIL: ar moving an element
FAIL: ar unique symbol in archive
Running /tmp/hpautotest-binutils/bsrc/src/binutils/testsuite/binutils-all/arm/objdump.exp ...
Running /tmp/hpautotest-binutils/bsrc/src/binutils/testsuite/binutils-all/bfin/objdump.exp ...
Running /tmp/hpautotest-binutils/bsrc/src/binutils/testsuite/binutils-all/compress.exp ...
FAIL: objcopy (objcopy decompress debug sections in archive)
FAIL: objcopy (objcopy compress debug sections in archive)
Comment 2 H.J. Lu 2013-02-15 18:20:38 UTC
diff --git a/bfd/archive.c b/bfd/archive.c
index e4183ea..4b6a81c 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -619,6 +617,7 @@ _bfd_append_relative_path (bfd *arch, char *elt_name)
 bfd *
 _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos)
 {
+  static file_ptr prev_filepos;
   struct areltdata *new_areldata;
   bfd *n_nfd;
   char *filename;
@@ -626,6 +625,12 @@ _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos)
   n_nfd = _bfd_look_for_bfd_in_cache (archive, filepos);
   if (n_nfd)
     return n_nfd;
+  /* PR15140: Prevent an inifnite recursion scanning a malformed nested archive
.  */
+  if (filepos == prev_filepos)
+    {
+      bfd_set_error (bfd_error_malformed_archive);
+      return NULL;
+    }
 
   if (0 > bfd_seek (archive, filepos, SEEK_SET))
     return NULL;
@@ -634,6 +639,7 @@ _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos)
     return NULL;
 
   filename = new_areldata->filename;
+  prev_filepos = filepos;
 
   if (bfd_is_thin_archive (archive))
     {

fails to match any target after the first one.  For cris, the targets are:

a.out-cris elf32-us-cris elf32-cris ieee elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex

For x86-64, targets are

elf64-x86-64 elf32-i386 elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex
Comment 3 Sourceware Commits 2013-02-15 18:26:16 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2013-02-15 18:26:06

Modified files:
	bfd            : ChangeLog archive.c 

Log message:
	Don't allow a nested archive pointing to itself
	
	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.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5967&r2=1.5968
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/archive.c.diff?cvsroot=src&r1=1.97&r2=1.98
Comment 4 H.J. Lu 2013-02-15 19:29:08 UTC
Fixed.