Allow zero length archive elements.
authorNick Clifton <nickc@redhat.com>
Mon, 7 Mar 2016 17:29:25 +0000 (17:29 +0000)
committerNick Clifton <nickc@redhat.com>
Mon, 7 Mar 2016 17:29:25 +0000 (17:29 +0000)
bfd PR binutils/19775
* archive.c (bfd_generic_openr_next_archived_file): Allow zero
length elements in the archive.

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
binutils/ChangeLog
binutils/testsuite/binutils-all/ar.exp
binutils/testsuite/binutils-all/empty [new file with mode: 0644]

index d9d9e77df2e553db5077c66ca4ec7264755ff609..8c2da68af3481c1ee87162f0385e4ae34b73900c 100644 (file)
@@ -1,3 +1,9 @@
+2016-03-07  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/19775
+       * archive.c (bfd_generic_openr_next_archived_file): Allow zero
+       length elements in the archive.
+
 2016-03-07  Jiong Wang  <jiong.wang@arm.com>
 
        * elfnn-aarch64.c (elfNN_aarch64_check_relocs): Always create .got
index 68c18bff6a2c5eb5d2f14ad93518557a6290c1a8..53e295eb26c0b66741803400e92df496b096b527 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 7ba4aecfc4ee30a5123190f55209353f7184b749..918299a129858af237b4361d3b96e27884894516 100644 (file)
@@ -1,3 +1,10 @@
+2016-03-07  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-03-04  Matthew Wahab  <matthew.wahab@arm.com>
 
        * readelf.c (arm_attry_tag_FP_arch): Add "NEON for ARMv8.1".
index 508ae9c1d7562c8b0a2c090a93e35acdba733944..45be9b1b594b39624f3e010f50bf98892fb64549 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
This page took 0.029859 seconds and 4 git commands to generate.