mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-27 03:54:41 +08:00
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.
This commit is contained in:
parent
9c8d5b9a4f
commit
c8567a87a6
@ -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.
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user