/* objcopy.c -- copy object file from input to output, optionally massaging it.
- Copyright (C) 1991-2014 Free Software Foundation, Inc.
+ Copyright (C) 1991-2015 Free Software Foundation, Inc.
This file is part of GNU Binutils.
-U --disable-deterministic-archives\n\
Disable -D behavior (default)\n"));
fprintf (stream, _("\
- -R --remove-section=<name> Remove section <name> from the output\n\
+ -R --remove-section=<name> Also remove section <name> from the output\n\
-s --strip-all Remove all symbol and relocation information\n\
-g -S -d --strip-debug Remove all debugging symbols & sections\n\
--strip-dwo Remove all DWO sections\n\
return FALSE;
}
+static bfd_boolean
+is_nondebug_keep_contents_section (bfd *ibfd, asection *isection)
+{
+ /* Always keep ELF note sections. */
+ if (ibfd->xvec->flavour == bfd_target_elf_flavour)
+ return (elf_section_type (isection) == SHT_NOTE);
+
+ /* Always keep the .buildid section for PE/COFF.
+
+ Strictly, this should be written "always keep the section storing the debug
+ directory", but that may be the .text section for objects produced by some
+ tools, which it is not sensible to keep. */
+ if (ibfd->xvec->flavour == bfd_target_coff_flavour)
+ return (strcmp (bfd_get_section_name (ibfd, isection), ".buildid") == 0);
+
+ return FALSE;
+}
+
/* Return true if SYM is a hidden symbol. */
static bfd_boolean
bfd_boolean del = TRUE;
bfd_boolean ok_object;
+ /* PR binutils/17533: Do not allow directory traversal
+ outside of the current directory tree by archive members. */
+ if (! is_valid_archive_path (bfd_get_filename (this_element)))
+ {
+ non_fatal (_("illegal pathname found in archive member: %s"),
+ bfd_get_filename (this_element));
+ status = 1;
+ goto cleanup_and_exit;
+ }
+
/* Create an output file for this member. */
output_name = concat (dir, "/",
bfd_get_filename (this_element), (char *) 0);
{
output_name = make_tempdir (output_name);
if (output_name == NULL)
- fatal (_("cannot create tempdir for archive copying (error: %s)"),
- strerror (errno));
+ {
+ non_fatal (_("cannot create tempdir for archive copying (error: %s)"),
+ strerror (errno));
+ status = 1;
+ goto cleanup_and_exit;
+ }
l = (struct name_list *) xmalloc (sizeof (struct name_list));
l->name = output_name;
{
bfd_nonfatal_message (output_name, NULL, NULL, NULL);
status = 1;
- return;
+ goto cleanup_and_exit;
}
if (ok_object)
{
status = 1;
bfd_nonfatal_message (filename, NULL, NULL, NULL);
- return;
}
filename = bfd_get_filename (ibfd);
{
status = 1;
bfd_nonfatal_message (filename, NULL, NULL, NULL);
- return;
}
+ cleanup_and_exit:
/* Delete all the files that we opened. */
for (l = list; l != NULL; l = l->next)
{
flags = p->flags | (flags & (SEC_HAS_CONTENTS | SEC_RELOC));
else if (strip_symbols == STRIP_NONDEBUG
&& (flags & (SEC_ALLOC | SEC_GROUP)) != 0
- && !(ibfd->xvec->flavour == bfd_target_elf_flavour
- && elf_section_type (isection) == SHT_NOTE))
+ && !is_nondebug_keep_contents_section (ibfd, isection))
{
flags &= ~(SEC_HAS_CONTENTS | SEC_LOAD | SEC_GROUP);
if (obfd->xvec->flavour == bfd_target_elf_flavour)
int i;
char *output_file = NULL;
- while ((c = getopt_long (argc, argv, "I:O:F:K:N:R:o:sSpdgxXHhVvw",
+ while ((c = getopt_long (argc, argv, "I:O:F:K:N:R:o:sSpdgxXHhVvwDU",
strip_options, (int *) 0)) != EOF)
{
switch (c)
struct stat statbuf;
const bfd_arch_info_type *input_arch = NULL;
- while ((c = getopt_long (argc, argv, "b:B:i:I:j:K:N:s:O:d:F:L:G:R:SpgxXHhVvW:w",
+ while ((c = getopt_long (argc, argv, "b:B:i:I:j:K:N:s:O:d:F:L:G:R:SpgxXHhVvW:wDU",
copy_options, (int *) 0)) != EOF)
{
switch (c)