aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@gotplt.org>2020-12-07 20:48:23 +0530
committerSiddhesh Poyarekar <siddhesh@gotplt.org>2020-12-07 20:48:23 +0530
commit365f5fb6d0f0da83817431a275e99e6f6babbe04 (patch)
tree2fc2d6dfad654e6dba514065239d22be824b4d4a /bfd
parenta4915e8d6ceac18826d2c832cb1303690dc9f256 (diff)
downloadgdb-365f5fb6d0f0da83817431a275e99e6f6babbe04.zip
gdb-365f5fb6d0f0da83817431a275e99e6f6babbe04.tar.gz
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 'bfd')
-rw-r--r--bfd/ChangeLog6
-rw-r--r--bfd/bfd-in2.h2
-rw-r--r--bfd/opncls.c33
3 files changed, 41 insertions, 0 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 8a32d5c..99c275c 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2020-12-07 Siddhesh Poyarekar <siddhesh@sourceware.org>
+
+ PR 26945
+ * opncls.c (bfd_fdopenw): New function.
+ * bfd-in2.h: Regenerate.
+
2020-12-07 Alan Modra <amodra@gmail.com>
* elf32-csky.c (csky_relocate_contents): Correct negate test.
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 935ba53..48e3d9b 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -588,6 +588,8 @@ bfd *bfd_openr (const char *filename, const char *target);
bfd *bfd_fdopenr (const char *filename, const char *target, int fd);
+bfd *bfd_fdopenw (const char *filename, const char *target, int fd);
+
bfd *bfd_openstreamr (const char * filename, const char * target,
void * stream);
diff --git a/bfd/opncls.c b/bfd/opncls.c
index c2a1d2f..f7696b6 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -395,6 +395,39 @@ bfd_fdopenr (const char *filename, const char *target, int fd)
/*
FUNCTION
+ bfd_fdopenw
+
+SYNOPSIS
+ bfd *bfd_fdopenw (const char *filename, const char *target, int fd);
+
+DESCRIPTION
+ <<bfd_fdopenw>> is exactly like <<bfd_fdopenr>> with the exception that
+ the resulting BFD is suitable for output.
+*/
+
+bfd *
+bfd_fdopenw (const char *filename, const char *target, int fd)
+{
+ bfd *out = bfd_fdopenr (filename, target, fd);
+
+ if (out != NULL)
+ {
+ if (!bfd_write_p (out))
+ {
+ close (fd);
+ _bfd_delete_bfd (out);
+ out = NULL;
+ bfd_set_error (bfd_error_invalid_operation);
+ }
+ else
+ out->direction = write_direction;
+ }
+
+ return out;
+}
+
+/*
+FUNCTION
bfd_openstreamr
SYNOPSIS