diff options
author | Alan Modra <amodra@gmail.com> | 2022-11-09 16:37:42 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2022-11-09 17:31:41 +1030 |
commit | 2d4989e98ee5e63b76ce3e35b0e02baaee2f50cb (patch) | |
tree | 98730a35dbee4cae3b82f83999a0e86d46f13923 | |
parent | a8d181c0fdae61f788d0332e3d9c0cff4b80eaa5 (diff) | |
download | gdb-2d4989e98ee5e63b76ce3e35b0e02baaee2f50cb.zip gdb-2d4989e98ee5e63b76ce3e35b0e02baaee2f50cb.tar.gz gdb-2d4989e98ee5e63b76ce3e35b0e02baaee2f50cb.tar.bz2 |
Re: Fuzzed files in archives
Like commit ffbe89531c2e this avoids more silliness writing output
that is going to be deleted. bfd_close and bfd_close_all_done differ
in that only the former calls _bfd_write_contents.
* objcopy.c (copy_archive): Don't call bfd_close for elements
that are going to be deleted, call bfd_close_all_done instead.
Do the same for the archive itself.
-rw-r--r-- | binutils/objcopy.c | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 03350ba..d886e3a 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -3670,23 +3670,16 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, if (del && bfd_get_arch (this_element) == bfd_arch_unknown) /* Try again as an unknown object file. */ ok_object = false; - else if (!bfd_close (output_bfd)) - { - bfd_nonfatal_message (output_name, NULL, NULL, NULL); - /* Error in new object file. Don't change archive. */ - status = 1; - } } if (!ok_object) + del = !copy_unknown_object (this_element, output_bfd); + + if (!(ok_object && !del ? bfd_close : bfd_close_all_done) (output_bfd)) { - del = !copy_unknown_object (this_element, output_bfd); - if (!bfd_close_all_done (output_bfd)) - { - bfd_nonfatal_message (output_name, NULL, NULL, NULL); - /* Error in new object file. Don't change archive. */ - status = 1; - } + bfd_nonfatal_message (output_name, NULL, NULL, NULL); + /* Error in new object file. Don't change archive. */ + status = 1; } if (del) @@ -3717,7 +3710,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, *ptr = NULL; filename = bfd_get_filename (obfd); - if (!bfd_close (obfd)) + if (!(status == 0 ? bfd_close : bfd_close_all_done) (obfd)) { status = 1; bfd_nonfatal_message (filename, NULL, NULL, NULL); |