X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=binutils%2Far.c;h=85b342a6502768be49dd2b97362dde96957a6099;hb=612f258a491539f36c618030cc558e83e7d58b4e;hp=0af7954a47a2574f6a7cddac6454abe6f77b3bf4;hpb=197245e341aeb1b5da8ee5fbe5d6c49de650fb89;p=deliverable%2Fbinutils-gdb.git diff --git a/binutils/ar.c b/binutils/ar.c index 0af7954a47..85b342a650 100644 --- a/binutils/ar.c +++ b/binutils/ar.c @@ -1,5 +1,5 @@ /* ar.c - Archive modify and extract. - Copyright (C) 1991-2019 Free Software Foundation, Inc. + Copyright (C) 1991-2020 Free Software Foundation, Inc. This file is part of GNU Binutils. @@ -225,7 +225,7 @@ map_over_members (bfd *arch, void (*function)(bfd *), char **files, int count) if (head->archive_pass) continue; - filename = head->filename; + filename = bfd_get_filename (head); if (filename == NULL) { /* Some archive formats don't get the filenames filled in @@ -1070,6 +1070,18 @@ open_output_file (bfd * abfd) { output_filename = bfd_get_filename (abfd); + /* PR binutils/17533: Do not allow directory traversal + outside of the current directory tree - unless the + user has explicitly specified an output directory. */ + if (! is_valid_archive_path (output_filename)) + { + char * base = (char *) lbasename (output_filename); + + non_fatal (_("illegal output pathname for archive member: %s, using '%s' instead"), + output_filename, base); + output_filename = base; + } + if (output_dir) { size_t len = strlen (output_dir); @@ -1083,18 +1095,10 @@ open_output_file (bfd * abfd) output_filename = concat (output_dir, "/", output_filename, NULL); } } - - /* PR binutils/17533: Do not allow directory traversal - outside of the current directory tree. */ - if (! is_valid_archive_path (output_filename)) - { - char * base = (char *) lbasename (output_filename); - - non_fatal (_("illegal output pathname for archive member: %s, using '%s' instead"), - output_filename, base); - output_filename = base; - } + if (verbose) + printf ("x - %s\n", output_filename); + FILE * ostream = fopen (output_filename, FOPEN_WB); if (ostream == NULL) { @@ -1126,9 +1130,6 @@ extract_file (bfd *abfd) fatal (_("internal stat error on %s"), bfd_get_filename (abfd)); size = buf.st_size; - if (verbose) - printf ("x - %s\n", bfd_get_filename (abfd)); - bfd_seek (abfd, (file_ptr) 0, SEEK_SET); output_file = NULL; @@ -1281,7 +1282,7 @@ get_pos_bfd (bfd **contents, enum pos default_pos, const char *default_posname) else { for (; *after_bfd; after_bfd = &(*after_bfd)->archive_next) - if (FILENAME_CMP ((*after_bfd)->filename, realposname) == 0) + if (FILENAME_CMP (bfd_get_filename (*after_bfd), realposname) == 0) { if (realpos == pos_after) after_bfd = &(*after_bfd)->archive_next; @@ -1320,7 +1321,7 @@ delete_members (bfd *arch, char **files_to_delete) while (*current_ptr_ptr) { if (FILENAME_CMP (normalize (*files_to_delete, arch), - (*current_ptr_ptr)->filename) == 0) + bfd_get_filename (*current_ptr_ptr)) == 0) { ++match_count; if (counted_name_mode @@ -1375,7 +1376,7 @@ move_members (bfd *arch, char **files_to_move) { bfd *current_ptr = *current_ptr_ptr; if (FILENAME_CMP (normalize (*files_to_move, arch), - current_ptr->filename) == 0) + bfd_get_filename (current_ptr)) == 0) { /* Move this file to the end of the list - first cut from where it is. */ @@ -1397,7 +1398,8 @@ move_members (bfd *arch, char **files_to_move) current_ptr_ptr = &((*current_ptr_ptr)->archive_next); } /* xgettext:c-format */ - fatal (_("no entry %s in archive %s!"), *files_to_move, arch->filename); + fatal (_("no entry %s in archive %s!"), *files_to_move, + bfd_get_filename (arch)); next_file:; } @@ -1427,7 +1429,7 @@ replace_members (bfd *arch, char **files_to_move, bfd_boolean quick) /* For compatibility with existing ar programs, we permit the same file to be added multiple times. */ if (FILENAME_CMP (normalize (*files_to_move, arch), - normalize (current->filename, arch)) == 0 + normalize (bfd_get_filename (current), arch)) == 0 && current->arelt_data != NULL) { if (newer_only) @@ -1443,14 +1445,14 @@ replace_members (bfd *arch, char **files_to_move, bfd_boolean quick) if (bfd_stat_arch_elt (current, &asbuf) != 0) /* xgettext:c-format */ fatal (_("internal stat error on %s"), - current->filename); + bfd_get_filename (current)); if (fsbuf.st_mtime <= asbuf.st_mtime) goto next_file; } after_bfd = get_pos_bfd (&arch->archive_next, pos_after, - current->filename); + bfd_get_filename (current)); if (ar_emul_replace (after_bfd, *files_to_move, target, verbose)) {