diff options
author | Siddhesh Poyarekar <siddhesh@gotplt.org> | 2020-12-07 20:48:23 +0530 |
---|---|---|
committer | Siddhesh Poyarekar <siddhesh@gotplt.org> | 2020-12-07 20:48:23 +0530 |
commit | 365f5fb6d0f0da83817431a275e99e6f6babbe04 (patch) | |
tree | 2fc2d6dfad654e6dba514065239d22be824b4d4a /binutils/ar.c | |
parent | a4915e8d6ceac18826d2c832cb1303690dc9f256 (diff) | |
download | fsf-binutils-gdb-365f5fb6d0f0da83817431a275e99e6f6babbe04.zip fsf-binutils-gdb-365f5fb6d0f0da83817431a275e99e6f6babbe04.tar.gz fsf-binutils-gdb-365f5fb6d0f0da83817431a275e99e6f6babbe04.tar.bz2 |
binutils: Use file descriptors from make_tempname
The purpose of creating a temporary file securely using mkstemp is
defeated if it is closed in make_tempname and reopened later for use;
it is as good as using mktemp. Get the file descriptor instead and
then use it to create the BFD object.
bfd/
* opncls.c (bfd_fdopenw): New function.
* bfd-in2.h: Regenerate.
binutils/
* bucomm.c (make_tempname): Add argument to return file
descriptor.
* bucomm.h (make_tempname): Likewise.
* ar.c: Include libbfd.h.
(write_archive): Adjust for change in make_tempname. Call
bfd_fdopenw instead of bfd_openw.
* objcopy.c: Include libbfd.h.
(copy_file): New argument OFD. Use bfd_fdopenw instead of
bfd_openw.
(strip_main): Adjust for change in make_tempname and
copy_file.
(copy_main): Likewise.
Diffstat (limited to 'binutils/ar.c')
-rw-r--r-- | binutils/ar.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/binutils/ar.c b/binutils/ar.c index 7d279d6..2253242 100644 --- a/binutils/ar.c +++ b/binutils/ar.c @@ -25,6 +25,7 @@ #include "sysdep.h" #include "bfd.h" +#include "libbfd.h" #include "libiberty.h" #include "progress.h" #include "getopt.h" @@ -1252,20 +1253,24 @@ write_archive (bfd *iarch) bfd *obfd; char *old_name, *new_name; bfd *contents_head = iarch->archive_next; + int ofd = -1; old_name = (char *) xmalloc (strlen (bfd_get_filename (iarch)) + 1); strcpy (old_name, bfd_get_filename (iarch)); - new_name = make_tempname (old_name); + new_name = make_tempname (old_name, &ofd); if (new_name == NULL) bfd_fatal (_("could not create temporary file whilst writing archive")); output_filename = new_name; - obfd = bfd_openw (new_name, bfd_get_target (iarch)); + obfd = bfd_fdopenw (new_name, bfd_get_target (iarch), ofd); if (obfd == NULL) - bfd_fatal (old_name); + { + close (ofd); + bfd_fatal (old_name); + } output_bfd = obfd; |