aboutsummaryrefslogtreecommitdiff
path: root/binutils/arsup.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2021-02-23 12:10:58 +1030
committerAlan Modra <amodra@gmail.com>2021-02-24 09:34:42 +1030
commitc42c71a1527dd70417d3966dce7ba9edbcf4bdb4 (patch)
treec84495ca493b5b03e8e144701fcc276a01d736d5 /binutils/arsup.c
parentcca8873dd5a6015d5557ea44bc1ea9c252435a29 (diff)
downloadgdb-c42c71a1527dd70417d3966dce7ba9edbcf4bdb4.zip
gdb-c42c71a1527dd70417d3966dce7ba9edbcf4bdb4.tar.gz
gdb-c42c71a1527dd70417d3966dce7ba9edbcf4bdb4.tar.bz2
Use make_tempname file descriptor in smart_rename
This patch makes use of the temp file descriptor in smart_rename rather than reopening the file. I don't believe there is a security issue in reopening the file, but this way is one less directory operation. The patch also attempts to preserve S_ISUID and S_ISGID. PR 27456 * bucomm.h (smart_rename): Update prototype. * rename.c (smart_rename): Add fromfd and preserve_dates params. Pass fromfd and target_stat to simple_copy. Call set_times when preserve_dates. (simple_copy): Accept fromfd rather than from filename. Add target_stat param. Rewind fromfd rather than opening. Open "to" file without O_CREAT. Try to preserve S_ISUID and S_ISGID. * ar.c (write_archive): Rename ofd to tmpfd. Dup tmpfd before closing output temp file, and pass tmpfd to smart_rename. * arsup.c (temp_fd): Rename from real_fd. (ar_save): Dup temp_fd and pass to smart_rename. * objcopy.c (strip_main, copy_main): Likewise, and pass preserve_dates.
Diffstat (limited to 'binutils/arsup.c')
-rw-r--r--binutils/arsup.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/binutils/arsup.c b/binutils/arsup.c
index f7ce8f0..9982484 100644
--- a/binutils/arsup.c
+++ b/binutils/arsup.c
@@ -43,7 +43,7 @@ extern int deterministic;
static bfd *obfd;
static char *real_name;
static char *temp_name;
-static int real_ofd;
+static int temp_fd;
static FILE *outfile;
static void
@@ -152,7 +152,7 @@ void
ar_open (char *name, int t)
{
real_name = xstrdup (name);
- temp_name = make_tempname (real_name, &real_ofd);
+ temp_name = make_tempname (real_name, &temp_fd);
if (temp_name == NULL)
{
@@ -162,7 +162,7 @@ ar_open (char *name, int t)
return;
}
- obfd = bfd_fdopenw (temp_name, NULL, real_ofd);
+ obfd = bfd_fdopenw (temp_name, NULL, temp_fd);
if (!obfd)
{
@@ -348,6 +348,7 @@ ar_save (void)
if (deterministic > 0)
obfd->flags |= BFD_DETERMINISTIC_OUTPUT;
+ temp_fd = dup (temp_fd);
bfd_close (obfd);
if (stat (real_name, &target_stat) != 0)
@@ -363,7 +364,7 @@ ar_save (void)
}
}
- smart_rename (temp_name, real_name, NULL);
+ smart_rename (temp_name, real_name, temp_fd, NULL, FALSE);
obfd = 0;
free (temp_name);
free (real_name);