Prevent archive memebers with illegal pathnames from being extracted from an archive.

PR binutils/17552, binutils/17533
	* bucomm.c (is_valid_archive_path): New function.  Returns false
	for absolute pathnames and pathnames that include /../.
	* bucomm.h (is_valid_archive_path): Add prototype.
	* ar.c (extract_file): Use new function to check for valid
	pathnames when extracting files from an archive.
	* objcopy.c (copy_archive): Likewise.
	* doc/binutils.texi: Update documentation to mention the
	limitation on pathname of archive members.
This commit is contained in:
Nick Clifton
2014-11-06 14:49:10 +00:00
parent 834107255b
commit dd9b91de21
6 changed files with 65 additions and 7 deletions

View File

@ -1034,6 +1034,15 @@ extract_file (bfd *abfd)
bfd_size_type size;
struct stat buf;
/* PR binutils/17533: Do not allow directory traversal
outside of the current directory tree. */
if (! is_valid_archive_path (bfd_get_filename (abfd)))
{
non_fatal (_("illegal pathname found in archive member: %s"),
bfd_get_filename (abfd));
return;
}
if (bfd_stat_arch_elt (abfd, &buf) != 0)
/* xgettext:c-format */
fatal (_("internal stat error on %s"), bfd_get_filename (abfd));