]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Allow zero length archive elements
authorAlan Modra <amodra@gmail.com>
Wed, 9 Mar 2016 06:31:54 +0000 (17:01 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 9 Mar 2016 06:31:54 +0000 (17:01 +1030)
bfd/
PR binutils/19775
* archive.c (bfd_generic_openr_next_archived_file): Allow zero
length elements in the archive.
* coff-alpha.c (alpha_ecoff_openr_next_archived_file): Likewise.

binutils/
PR binutils/19775
* testsuite/binutils-all/ar.exp (proc empty_archive): New proc.
Run the new proc.
* testsuite/binutils-all/empty: New, empty, file.

bfd/ChangeLog
bfd/archive.c
bfd/coff-alpha.c
binutils/ChangeLog
binutils/testsuite/binutils-all/ar.exp
binutils/testsuite/binutils-all/empty [new file with mode: 0644]

index ce32d43ce0d7a978787955a795d0a028af1f8219..0a08b5563840fb4555a90f07537f94f9b4e732ac 100644 (file)
@@ -1,3 +1,11 @@
+2016-03-09  Nick Clifton  <nickc@redhat.com>
+           Alan Modra  <amodra@gmail.com>
+
+       PR binutils/19775
+       * archive.c (bfd_generic_openr_next_archived_file): Allow zero
+       length elements in the archive.
+       * coff-alpha.c (alpha_ecoff_openr_next_archived_file): Likewise.
+
 2016-03-01  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/19752
index b3d03d36daf62ddfa40d33fd9bb489172c29c630..1fc3a946405f7aada5295c116b2a6299ec86baa0 100644 (file)
@@ -802,7 +802,7 @@ bfd_generic_openr_next_archived_file (bfd *archive, bfd *last_file)
             Note that last_file->origin can be odd in the case of
             BSD-4.4-style element with a long odd size.  */
          filestart += filestart % 2;
-         if (filestart <= last_file->proxy_origin)
+         if (filestart < last_file->proxy_origin)
            {
              /* Prevent looping.  See PR19256.  */
              bfd_set_error (bfd_error_malformed_archive);
index 7478f2f320d39a81f2d390de36ce44b42fd756ba..fffb9f71ca6f0c4b618113fa66e736960ee3d940 100644 (file)
@@ -2208,7 +2208,7 @@ alpha_ecoff_openr_next_archived_file (bfd *archive, bfd *last_file)
         BSD-4.4-style element with a long odd size.  */
       filestart = last_file->proxy_origin + size;
       filestart += filestart % 2;
-      if (filestart <= last_file->proxy_origin)
+      if (filestart < last_file->proxy_origin)
        {
          /* Prevent looping.  See PR19256.  */
          bfd_set_error (bfd_error_malformed_archive);
index 4648d93520a78b5554868c144dd407f76911bcbb..b04c745d4a29c867a5ad927a4e17f021e67b09c6 100644 (file)
@@ -1,3 +1,10 @@
+2016-03-09  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/19775
+       * testsuite/binutils-all/ar.exp (proc empty_archive): New proc.
+       Run the new proc.
+       * testsuite/binutils-all/empty: New, empty, file.
+
 2016-02-12  H.J. Lu  <hongjiu.lu@intel.com>
 
        Backport from master
index 4c338743368dcf98f37ffd5c204d94bd0d9d007a..e9713506f358c0138385e71fbe4c8c224db37e4c 100644 (file)
@@ -555,6 +555,45 @@ proc move_an_element { } {
     pass $testname
 }
 
+# PR 19775: Test creating and listing archives with an empty element.
+
+proc empty_archive { } {
+    global AR
+    global srcdir
+    global subdir
+
+    set testname "archive with empty element"
+
+    # FIXME: There ought to be a way to dynamically create an empty file.
+    set empty $srcdir/$subdir/empty
+    
+    if [is_remote host] {
+       set archive artest.a
+       set objfile [remote_download host $empty]
+       remote_file host delete $archive
+    } else {
+       set archive tmpdir/artest.a
+       set objfile $empty
+    }
+
+    remote_file build delete tmpdir/artest.a
+
+    set got [binutils_run $AR "-r -c $archive ${objfile}"]
+    if ![string match "" $got] {
+       fail $testname
+       return
+    }
+
+    # This commmand used to fail with: "Malformed archive".
+    set got [binutils_run $AR "-t $archive"]
+    if ![string match "empty\r" $got] {
+       fail $testname
+       return
+    }
+
+    pass $testname
+}
+
 # Run the tests.
 
 # Only run the bfdtest checks if the programs exist.  Since these
@@ -574,6 +613,7 @@ argument_parsing
 deterministic_archive
 delete_an_element
 move_an_element
+empty_archive
 
 if { [is_elf_format]
      && ![istarget "*-*-hpux*"]
diff --git a/binutils/testsuite/binutils-all/empty b/binutils/testsuite/binutils-all/empty
new file mode 100644 (file)
index 0000000..e69de29