aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2024-01-26 11:54:08 +0000
committerNick Clifton <nickc@redhat.com>2024-01-26 11:54:08 +0000
commitc8567a87a60cf5820ebc5d98c025e91e2735f373 (patch)
tree48a1d8e5c6e0b24403f8adfd0b496d3a33e4c29a
parent9c8d5b9a4fe297b9b7490ae33a10e275d54f6e2a (diff)
downloadgdb-c8567a87a60cf5820ebc5d98c025e91e2735f373.zip
gdb-c8567a87a60cf5820ebc5d98c025e91e2735f373.tar.gz
gdb-c8567a87a60cf5820ebc5d98c025e91e2735f373.tar.bz2
Fix: Stripping Rust static libraries fails because of overly zealous illegal path check
PR 31250 * objcopy.c (copy_archive): Improve the handling of archives that contain elements with invalid pathnames.
-rw-r--r--binutils/ChangeLog6
-rw-r--r--binutils/objcopy.c26
2 files changed, 20 insertions, 12 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 80da519..438a45d 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,9 @@
+2024-01-26 Nick Clifton <nickc@redhat.com>
+
+ PR 31250
+ * objcopy.c (copy_archive): Improve the handling of archives that
+ contain elements with invalid pathnames.
+
2024-01-15 Nick Clifton <nickc@redhat.com>
* 2.42 branch point.
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index a85d262..a8e0f15 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -3672,21 +3672,25 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
struct stat buf;
int stat_status = 0;
bool ok_object;
+ const char *element_name;
+ element_name = bfd_get_filename (this_element);
/* 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)))
+ if (! is_valid_archive_path (element_name))
{
- non_fatal (_("illegal pathname found in archive member: %s"),
- bfd_get_filename (this_element));
- bfd_close (this_element);
- status = 1;
- goto cleanup_and_exit;
+ non_fatal (_("warning: illegal pathname found in archive member: %s"),
+ element_name);
+ /* PR binutils/31250: But there tools which create archives
+ containing absolute paths, so instead of failing here, try to
+ create a suitable alternative pathname. */
+ element_name = lbasename (element_name);
+ non_fatal (_("warning: using the basename of the member instead: %s"),
+ element_name);
}
/* Create an output file for this member. */
- output_name = concat (dir, "/",
- bfd_get_filename (this_element), (char *) 0);
+ output_name = concat (dir, "/", element_name, (char *) 0);
/* If the file already exists, make another temp dir. */
if (stat (output_name, &buf) >= 0)
@@ -3708,8 +3712,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
l->next = list;
l->obfd = NULL;
list = l;
- output_name = concat (tmpdir, "/",
- bfd_get_filename (this_element), (char *) 0);
+ output_name = concat (tmpdir, "/", element_name, (char *) 0);
}
if (preserve_dates)
@@ -3718,8 +3721,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target,
stat_status = bfd_stat_arch_elt (this_element, &buf);
if (stat_status != 0)
- non_fatal (_("internal stat error on %s"),
- bfd_get_filename (this_element));
+ non_fatal (_("internal stat error on %s"), element_name);
}
struct name_list *l = xmalloc (sizeof (*l));