aboutsummaryrefslogtreecommitdiff
path: root/binutils/ar.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2021-02-01 02:04:41 +1030
committerAlan Modra <amodra@gmail.com>2021-02-03 13:30:28 +1030
commit95b91a043aeaeb546d2fea556d84a2de1e917770 (patch)
treef4d1b89f8cbd5afa631d7110b49dec23546cb25e /binutils/ar.c
parent6955136728a68365bbb5e6e1327dff1654b2a0ca (diff)
downloadfsf-binutils-gdb-95b91a043aeaeb546d2fea556d84a2de1e917770.zip
fsf-binutils-gdb-95b91a043aeaeb546d2fea556d84a2de1e917770.tar.gz
fsf-binutils-gdb-95b91a043aeaeb546d2fea556d84a2de1e917770.tar.bz2
pr27270 and pr27284, ar segfaults and wrong file mode
PR 27270 PR 27284 PR 26945 * ar.c: Don't include libbfd.h. (write_archive): Replace xmalloc+strcpy with xstrdup. Use bfd_stat rather than fstat on iostream. Move stat and fd tests outside of _WIN32 ifdef. Delete skip_stat variable. * arsup.c (temp_name, real_ofd): New static variables. (ar_open): Use make_tempname and bfd_fdopenw. (ar_save): Adjust to suit ar_open changes. Move stat output of _WIN32 ifdef. * objcopy.c: Don't include libbfd.h. (copy_file): Use bfd_stat.
Diffstat (limited to 'binutils/ar.c')
-rw-r--r--binutils/ar.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/binutils/ar.c b/binutils/ar.c
index 24ff092..0ecfa33 100644
--- a/binutils/ar.c
+++ b/binutils/ar.c
@@ -25,7 +25,6 @@
#include "sysdep.h"
#include "bfd.h"
-#include "libbfd.h"
#include "libiberty.h"
#include "progress.h"
#include "getopt.h"
@@ -1255,10 +1254,8 @@ write_archive (bfd *iarch)
bfd *contents_head = iarch->archive_next;
int ofd = -1;
struct stat target_stat;
- bfd_boolean skip_stat = FALSE;
- old_name = (char *) xmalloc (strlen (bfd_get_filename (iarch)) + 1);
- strcpy (old_name, bfd_get_filename (iarch));
+ old_name = xstrdup (bfd_get_filename (iarch));
new_name = make_tempname (old_name, &ofd);
if (new_name == NULL)
@@ -1303,11 +1300,9 @@ write_archive (bfd *iarch)
#if !defined (_WIN32) || defined (__CYGWIN32__)
ofd = dup (ofd);
- if (iarch == NULL || iarch->iostream == NULL)
- skip_stat = TRUE;
- else if (ofd == -1 || fstat (fileno ((FILE *) iarch->iostream), &target_stat) != 0)
- bfd_fatal (old_name);
#endif
+ if (ofd == -1 || bfd_stat (iarch, &target_stat) != 0)
+ bfd_fatal (old_name);
if (!bfd_close (obfd))
bfd_fatal (old_name);
@@ -1318,7 +1313,7 @@ write_archive (bfd *iarch)
/* We don't care if this fails; we might be creating the archive. */
bfd_close (iarch);
- if (smart_rename (new_name, old_name, ofd, skip_stat ? NULL : &target_stat, 0) != 0)
+ if (smart_rename (new_name, old_name, ofd, &target_stat, 0) != 0)
xexit (1);
free (old_name);
free (new_name);