Author: mm Date: Thu Jan 5 11:44:55 2012 New Revision: 229588 URL: http://svn.freebsd.org/changeset/base/229588
Log: MFC r228744, r228745, r228748: MFC r228744 [1]: Merge vendor revision 3723: Fixes extraction of Zip entries that use length-at-end without specifying either the compressed or uncompressed length. In particular, fixes bsdtar extraction of such files. Reported by: Patrick Lamaiziere <patf...@davenulle.org> (freebsd-stable@) MFC r228745: Update libarchive, tar and cpio to version 2.8.5 The following additional vendor revisions are applied: Revision 3740: Use archive_clear_error() to clear the error markers. Obtained from: http://code.google.com/p/libarchive MFC r228748: Sync libarchive with vendor branch release/2.8: 3730: Fix issue 174 (Windows path names, not relevant for FreeBSD) 3734: Merge r1989: archive_clear_error should set errno to 0. 3735: Merge r3247 from trunk: Clear errors before returning from archive_read_support_format_all() 3799: Check the position before dereferencing the pointer. This avoids dereferencing one byte past the end of a string 3824: Merge r3823 from trunk for issue 199 (hang in iso9660 reading) Obtained from: http://code.google.com/p/libarchive Added: stable/9/lib/libarchive/test/test_read_format_iso_Z.c - copied unchanged from r228745, head/lib/libarchive/test/test_read_format_iso_Z.c Deleted: stable/9/lib/libarchive/test/test_read_format_iso_gz.c Modified: stable/9/lib/libarchive/archive.h stable/9/lib/libarchive/archive_read.c stable/9/lib/libarchive/archive_read_extract.c stable/9/lib/libarchive/archive_read_support_compression_bzip2.c stable/9/lib/libarchive/archive_read_support_compression_uu.c stable/9/lib/libarchive/archive_read_support_format_all.c stable/9/lib/libarchive/archive_read_support_format_cpio.c stable/9/lib/libarchive/archive_read_support_format_iso9660.c stable/9/lib/libarchive/archive_read_support_format_tar.c stable/9/lib/libarchive/archive_read_support_format_zip.c stable/9/lib/libarchive/archive_string.c stable/9/lib/libarchive/archive_string.h stable/9/lib/libarchive/archive_util.c stable/9/lib/libarchive/archive_write_disk.c stable/9/lib/libarchive/archive_write_set_compression_xz.c stable/9/lib/libarchive/archive_write_set_format_ar.c stable/9/lib/libarchive/archive_write_set_format_shar.c stable/9/lib/libarchive/archive_write_set_format_ustar.c stable/9/lib/libarchive/config_freebsd.h stable/9/lib/libarchive/libarchive-formats.5 stable/9/lib/libarchive/libarchive.3 stable/9/lib/libarchive/test/Makefile stable/9/lib/libarchive/test/test_compat_zip.c stable/9/usr.bin/cpio/Makefile stable/9/usr.bin/tar/Makefile stable/9/usr.bin/tar/tree.c Directory Properties: stable/9/lib/libarchive/ (props changed) stable/9/usr.bin/cpio/ (props changed) stable/9/usr.bin/tar/ (props changed) Modified: stable/9/lib/libarchive/archive.h ============================================================================== --- stable/9/lib/libarchive/archive.h Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive.h Thu Jan 5 11:44:55 2012 (r229588) @@ -52,7 +52,7 @@ /* These should match the types used in 'struct stat' */ #if defined(_WIN32) && !defined(__CYGWIN__) #define __LA_INT64_T __int64 -# if defined(_SSIZE_T_DEFINED) +# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_) # define __LA_SSIZE_T ssize_t # elif defined(_WIN64) # define __LA_SSIZE_T __int64 @@ -98,6 +98,13 @@ # define __LA_DECL #endif +#if defined(__GNUC__) && __GNUC__ >= 3 +#define __LA_PRINTF(fmtarg, firstvararg) \ + __attribute__((__format__ (__printf__, fmtarg, firstvararg))) +#else +#define __LA_PRINTF(fmtarg, firstvararg) /* nothing */ +#endif + #ifdef __cplusplus extern "C" { #endif @@ -129,13 +136,13 @@ extern "C" { * (ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000) * #endif */ -#define ARCHIVE_VERSION_NUMBER 2008004 +#define ARCHIVE_VERSION_NUMBER 2008005 __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_STRING "libarchive 2.8.4" +#define ARCHIVE_VERSION_STRING "libarchive 2.8.5" __LA_DECL const char * archive_version_string(void); #if ARCHIVE_VERSION_NUMBER < 3000000 @@ -717,7 +724,7 @@ __LA_DECL const char *archive_format_nam __LA_DECL int archive_format(struct archive *); __LA_DECL void archive_clear_error(struct archive *); __LA_DECL void archive_set_error(struct archive *, int _err, - const char *fmt, ...); + const char *fmt, ...) __LA_PRINTF(3, 4); __LA_DECL void archive_copy_error(struct archive *dest, struct archive *src); __LA_DECL int archive_file_count(struct archive *); Modified: stable/9/lib/libarchive/archive_read.c ============================================================================== --- stable/9/lib/libarchive/archive_read.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_read.c Thu Jan 5 11:44:55 2012 (r229588) @@ -715,7 +715,7 @@ archive_read_data_block(struct archive * /* * Close the file and release most resources. * - * Be careful: client might just call read_new and then read_finish. + * Be careful: client might just call read_new and then read_free. * Don't assume we actually read anything or performed any non-trivial * initialization. */ Modified: stable/9/lib/libarchive/archive_read_extract.c ============================================================================== --- stable/9/lib/libarchive/archive_read_extract.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_read_extract.c Thu Jan 5 11:44:55 2012 (r229588) @@ -108,7 +108,7 @@ archive_read_extract2(struct archive *_a if (r != ARCHIVE_OK) /* If _write_header failed, copy the error. */ archive_copy_error(&a->archive, ad); - else if (archive_entry_size(entry) > 0) + else if (!archive_entry_size_is_set(entry) || archive_entry_size(entry) > 0) /* Otherwise, pour data into the entry. */ r = copy_data(_a, ad); r2 = archive_write_finish_entry(ad); Modified: stable/9/lib/libarchive/archive_read_support_compression_bzip2.c ============================================================================== --- stable/9/lib/libarchive/archive_read_support_compression_bzip2.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_read_support_compression_bzip2.c Thu Jan 5 11:44:55 2012 (r229588) @@ -350,4 +350,4 @@ bzip2_filter_close(struct archive_read_f return (ret); } -#endif /* HAVE_BZLIB_H */ +#endif /* HAVE_BZLIB_H && BZ_CONFIG_ERROR */ Modified: stable/9/lib/libarchive/archive_read_support_compression_uu.c ============================================================================== --- stable/9/lib/libarchive/archive_read_support_compression_uu.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_read_support_compression_uu.c Thu Jan 5 11:44:55 2012 (r229588) @@ -488,9 +488,9 @@ read_more: switch (uudecode->state) { default: case ST_FIND_HEAD: - if (len - nl > 13 && memcmp(b, "begin ", 6) == 0) + if (len - nl >= 11 && memcmp(b, "begin ", 6) == 0) l = 6; - else if (len - nl > 18 && + else if (len - nl >= 18 && memcmp(b, "begin-base64 ", 13) == 0) l = 13; else Modified: stable/9/lib/libarchive/archive_read_support_format_all.c ============================================================================== --- stable/9/lib/libarchive/archive_read_support_format_all.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_read_support_format_all.c Thu Jan 5 11:44:55 2012 (r229588) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2003-2007 Tim Kientzle + * Copyright (c) 2003-2011 Tim Kientzle * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -39,5 +39,13 @@ archive_read_support_format_all(struct a archive_read_support_format_tar(a); archive_read_support_format_xar(a); archive_read_support_format_zip(a); + + /* Note: We always return ARCHIVE_OK here, even if some of the + * above return ARCHIVE_WARN. The intent here is to enable + * "as much as possible." Clients who need specific + * compression should enable those individually so they can + * verify the level of support. */ + /* Clear any warning messages set by the above functions. */ + archive_clear_error(a); return (ARCHIVE_OK); } Modified: stable/9/lib/libarchive/archive_read_support_format_cpio.c ============================================================================== --- stable/9/lib/libarchive/archive_read_support_format_cpio.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_read_support_format_cpio.c Thu Jan 5 11:44:55 2012 (r229588) @@ -264,9 +264,9 @@ archive_read_format_cpio_read_header(str /* Compare name to "TRAILER!!!" to test for end-of-archive. */ if (namelength == 11 && strcmp((const char *)h, "TRAILER!!!") == 0) { - /* TODO: Store file location of start of block. */ - archive_set_error(&a->archive, 0, NULL); - return (ARCHIVE_EOF); + /* TODO: Store file location of start of block. */ + archive_clear_error(&a->archive); + return (ARCHIVE_EOF); } /* Detect and record hardlinks to previously-extracted entries. */ Modified: stable/9/lib/libarchive/archive_read_support_format_iso9660.c ============================================================================== --- stable/9/lib/libarchive/archive_read_support_format_iso9660.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_read_support_format_iso9660.c Thu Jan 5 11:44:55 2012 (r229588) @@ -302,6 +302,8 @@ struct file_info { struct file_info *first; struct file_info **last; } rede_files; + /* To check a ininity loop. */ + struct file_info *loop_by; }; struct heap_queue { @@ -934,14 +936,14 @@ read_children(struct archive_read *a, st archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Ignoring out-of-order directory (%s) %jd > %jd", parent->name.s, - iso9660->current_position, - parent->offset); + (intmax_t)iso9660->current_position, + (intmax_t)parent->offset); return (ARCHIVE_WARN); } if (parent->offset + parent->size > iso9660->volume_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Directory is beyond end-of-media: %s", - parent->name); + parent->name.s); return (ARCHIVE_WARN); } if (iso9660->current_position < parent->offset) { @@ -1139,7 +1141,7 @@ archive_read_format_iso9660_read_header( if (file->offset + file->size > iso9660->volume_size) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "File is beyond end-of-media: %s", file->name); + "File is beyond end-of-media: %s", file->name.s); iso9660->entry_bytes_remaining = 0; iso9660->entry_sparse_offset = 0; return (ARCHIVE_WARN); @@ -1198,10 +1200,10 @@ archive_read_format_iso9660_read_header( if ((file->mode & AE_IFMT) != AE_IFDIR && file->offset < iso9660->current_position) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "Ignoring out-of-order file @%x (%s) %jd < %jd", - file, + "Ignoring out-of-order file (%s) %jd < %jd", iso9660->pathname.s, - file->offset, iso9660->current_position); + (intmax_t)file->offset, + (intmax_t)iso9660->current_position); iso9660->entry_bytes_remaining = 0; iso9660->entry_sparse_offset = 0; return (ARCHIVE_WARN); @@ -1524,8 +1526,8 @@ archive_read_format_iso9660_read_data(st archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Ignoring out-of-order file (%s) %jd < %jd", iso9660->pathname.s, - iso9660->entry_content->offset, - iso9660->current_position); + (intmax_t)iso9660->entry_content->offset, + (intmax_t)iso9660->current_position); *buff = NULL; *size = 0; *offset = iso9660->entry_sparse_offset; @@ -1626,8 +1628,8 @@ parse_file_info(struct archive_read *a, */ if (location > 0 && (location + ((fsize + iso9660->logical_block_size -1) - / iso9660->logical_block_size)) > - (unsigned int)iso9660->volume_block) { + / iso9660->logical_block_size)) + > (uint32_t)iso9660->volume_block) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Invalid location of extent of file"); return (NULL); @@ -2699,8 +2701,14 @@ rede_add_entry(struct file_info *file) struct file_info *re; re = file->parent; - while (re != NULL && !re->re) + while (re != NULL && !re->re) { + /* Sanity check to prevent a infinity loop + * cause by a currupted iso file. */ + if (re->loop_by == file) + return (-1); + re->loop_by = file; re = re->parent; + } if (re == NULL) return (-1); Modified: stable/9/lib/libarchive/archive_read_support_format_tar.c ============================================================================== --- stable/9/lib/libarchive/archive_read_support_format_tar.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_read_support_format_tar.c Thu Jan 5 11:44:55 2012 (r229588) @@ -576,7 +576,7 @@ tar_read_header(struct archive_read *a, h = __archive_read_ahead(a, 512, NULL); if (h != NULL) __archive_read_consume(a, 512); - archive_set_error(&a->archive, 0, NULL); + archive_clear_error(&a->archive); if (a->archive.archive_format_name == NULL) { a->archive.archive_format = ARCHIVE_FORMAT_TAR; a->archive.archive_format_name = "tar"; Modified: stable/9/lib/libarchive/archive_read_support_format_zip.c ============================================================================== --- stable/9/lib/libarchive/archive_read_support_format_zip.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_read_support_format_zip.c Thu Jan 5 11:44:55 2012 (r229588) @@ -211,7 +211,7 @@ archive_read_format_zip_bid(struct archi /* Get 4k of data beyond where we stopped. */ buff = __archive_read_ahead(a, offset + 4096, &bytes_avail); - if (bytes_avail < offset + 1) + if (buff == NULL) break; p = (const char *)buff + offset; while (p + 9 < (const char *)buff + bytes_avail) { Modified: stable/9/lib/libarchive/archive_string.c ============================================================================== --- stable/9/lib/libarchive/archive_string.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_string.c Thu Jan 5 11:44:55 2012 (r229588) @@ -152,7 +152,7 @@ __archive_strncat(struct archive_string /* Like strlen(p), except won't examine positions beyond p[n]. */ s = 0; pp = p; - while (*pp && s < n) { + while (s < n && *pp) { pp++; s++; } Modified: stable/9/lib/libarchive/archive_string.h ============================================================================== --- stable/9/lib/libarchive/archive_string.h Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_string.h Thu Jan 5 11:44:55 2012 (r229588) @@ -44,6 +44,8 @@ #include <wchar.h> #endif +#include "archive.h" + /* * Basic resizable/reusable string support a la Java's "StringBuffer." * @@ -134,10 +136,11 @@ void __archive_string_free(struct archiv /* Like 'vsprintf', but resizes the underlying string as necessary. */ void __archive_string_vsprintf(struct archive_string *, const char *, - va_list); + va_list) __LA_PRINTF(2, 0); #define archive_string_vsprintf __archive_string_vsprintf -void __archive_string_sprintf(struct archive_string *, const char *, ...); +void __archive_string_sprintf(struct archive_string *, const char *, ...) + __LA_PRINTF(2, 3); #define archive_string_sprintf __archive_string_sprintf /* Allocates a fresh buffer and converts as (assumed to be UTF-8) into it. Modified: stable/9/lib/libarchive/archive_util.c ============================================================================== --- stable/9/lib/libarchive/archive_util.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_util.c Thu Jan 5 11:44:55 2012 (r229588) @@ -155,6 +155,7 @@ archive_clear_error(struct archive *a) { archive_string_empty(&a->error_string); a->error = NULL; + a->archive_error_number = 0; } void Modified: stable/9/lib/libarchive/archive_write_disk.c ============================================================================== --- stable/9/lib/libarchive/archive_write_disk.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_write_disk.c Thu Jan 5 11:44:55 2012 (r229588) @@ -1513,6 +1513,22 @@ check_symlinks(struct archive_write_disk } #if defined(_WIN32) || defined(__CYGWIN__) +static int +guidword(const char *p, int n) +{ + int i; + + for (i = 0; i < n; i++) { + if ((*p >= '0' && *p <= '9') || + (*p >= 'a' && *p <= 'f') || + (*p >= 'A' && *p <= 'F')) + p++; + else + return (-1); + } + return (0); +} + /* * 1. Convert a path separator from '\' to '/' . * We shouldn't check multi-byte character directly because some @@ -1521,26 +1537,92 @@ check_symlinks(struct archive_write_disk * 2. Replace unusable characters in Windows with underscore('_'). * See also : http://msdn.microsoft.com/en-us/library/aa365247.aspx */ -static void +static int cleanup_pathname_win(struct archive_write_disk *a) { wchar_t wc; char *p; size_t alen, l; - alen = 0; - l = 0; - for (p = a->name; *p != '\0'; p++) { - ++alen; - if (*p == '\\') - l = 1; + p = a->name; + /* Skip leading "\\.\" or "\\?\" or "\\?\UNC\" or + * "\\?\Volume{GUID}\" + * (absolute path prefixes used by Windows API) */ + if ((p[0] == '\\' || p[0] == '/') && (p[1] == '\\' || p[1] == '/' ) && + (p[2] == '.' || p[2] == '?') && (p[3] == '\\' || p[3] == '/')) + { + /* A path begin with "\\?\UNC\" */ + if (p[2] == '?' && + (p[4] == 'U' || p[4] == 'u') && + (p[5] == 'N' || p[5] == 'n') && + (p[6] == 'C' || p[6] == 'c') && + (p[7] == '\\' || p[7] == '/')) + p += 8; + /* A path begin with "\\?\Volume{GUID}\" */ + else if (p[2] == '?' && + (p[4] == 'V' || p[4] == 'v') && + (p[5] == 'O' || p[5] == 'o') && + (p[6] == 'L' || p[6] == 'l') && + (p[7] == 'U' || p[7] == 'u') && + (p[8] == 'M' || p[8] == 'm') && + (p[9] == 'E' || p[9] == 'e') && + p[10] == '{') { + if (guidword(p+11, 8) == 0 && p[19] == '-' && + guidword(p+20, 4) == 0 && p[24] == '-' && + guidword(p+25, 4) == 0 && p[29] == '-' && + guidword(p+30, 4) == 0 && p[34] == '-' && + guidword(p+35, 12) == 0 && p[47] == '}' && + (p[48] == '\\' || p[48] == '/')) + p += 49; + else + p += 4; + /* A path begin with "\\.\PhysicalDriveX" */ + } else if (p[2] == '.' && + (p[4] == 'P' || p[4] == 'p') && + (p[5] == 'H' || p[5] == 'h') && + (p[6] == 'Y' || p[6] == 'y') && + (p[7] == 'S' || p[7] == 's') && + (p[8] == 'I' || p[8] == 'i') && + (p[9] == 'C' || p[9] == 'c') && + (p[9] == 'A' || p[9] == 'a') && + (p[9] == 'L' || p[9] == 'l') && + (p[9] == 'D' || p[9] == 'd') && + (p[9] == 'R' || p[9] == 'r') && + (p[9] == 'I' || p[9] == 'i') && + (p[9] == 'V' || p[9] == 'v') && + (p[9] == 'E' || p[9] == 'e') && + (p[10] >= '0' && p[10] <= '9') && + p[11] == '\0') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Path is a physical drive name"); + return (ARCHIVE_FAILED); + } else + p += 4; + } + + /* Skip leading drive letter from archives created + * on Windows. */ + if (((p[0] >= 'a' && p[0] <= 'z') || + (p[0] >= 'A' && p[0] <= 'Z')) && + p[1] == ':') { + if (p[2] == '\0') { + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, + "Path is a drive name"); + return (ARCHIVE_FAILED); + } + if (p[2] == '\\' || p[2] == '/') + p += 3; + } + + for (; *p != '\0'; p++) { /* Rewrite the path name if its character is a unusable. */ if (*p == ':' || *p == '*' || *p == '?' || *p == '"' || *p == '<' || *p == '>' || *p == '|') *p = '_'; } - if (alen == 0 || l == 0) - return; + alen = p - a->name; + if (alen == 0 || strchr(a->name, '\\') == NULL) + return (ARCHIVE_OK); /* * Convert path separator. */ @@ -1560,6 +1642,7 @@ cleanup_pathname_win(struct archive_writ p += l; alen -= l; } + return (ARCHIVE_OK); } #endif @@ -1583,7 +1666,8 @@ cleanup_pathname(struct archive_write_di } #if defined(_WIN32) || defined(__CYGWIN__) - cleanup_pathname_win(a); + if (cleanup_pathname_win(a) != ARCHIVE_OK) + return (ARCHIVE_FAILED); #endif /* Skip leading '/'. */ if (*src == '/') @@ -1730,7 +1814,7 @@ create_dir(struct archive_write_disk *a, if (unlink(path) != 0) { archive_set_error(&a->archive, errno, "Can't create directory '%s': " - "Conflicting file cannot be removed"); + "Conflicting file cannot be removed", path); return (ARCHIVE_FAILED); } } else if (errno != ENOENT && errno != ENOTDIR) { Modified: stable/9/lib/libarchive/archive_write_set_compression_xz.c ============================================================================== --- stable/9/lib/libarchive/archive_write_set_compression_xz.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_write_set_compression_xz.c Thu Jan 5 11:44:55 2012 (r229588) @@ -132,9 +132,10 @@ static int archive_compressor_xz_init_stream(struct archive_write *a, struct private_data *state) { + static const lzma_stream lzma_stream_init_data = LZMA_STREAM_INIT; int ret; - state->stream = (lzma_stream)LZMA_STREAM_INIT; + state->stream = lzma_stream_init_data; state->stream.next_out = state->compressed; state->stream.avail_out = state->compressed_buffer_size; if (a->archive.compression_code == ARCHIVE_COMPRESSION_XZ) Modified: stable/9/lib/libarchive/archive_write_set_format_ar.c ============================================================================== --- stable/9/lib/libarchive/archive_write_set_format_ar.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_write_set_format_ar.c Thu Jan 5 11:44:55 2012 (r229588) @@ -440,7 +440,7 @@ archive_write_ar_finish_entry(struct arc if (ar->entry_padding != 1) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Padding wrong size: %d should be 1 or 0", - ar->entry_padding); + (int)ar->entry_padding); return (ARCHIVE_WARN); } Modified: stable/9/lib/libarchive/archive_write_set_format_shar.c ============================================================================== --- stable/9/lib/libarchive/archive_write_set_format_shar.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_write_set_format_shar.c Thu Jan 5 11:44:55 2012 (r229588) @@ -537,8 +537,7 @@ archive_write_shar_finish_entry(struct a } if ((p = archive_entry_fflags_text(shar->entry)) != NULL) { - archive_string_sprintf(&shar->work, "chflags %s ", - p, archive_entry_pathname(shar->entry)); + archive_string_sprintf(&shar->work, "chflags %s ", p); shar_quote(&shar->work, archive_entry_pathname(shar->entry), 1); archive_strcat(&shar->work, "\n"); Modified: stable/9/lib/libarchive/archive_write_set_format_ustar.c ============================================================================== --- stable/9/lib/libarchive/archive_write_set_format_ustar.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/archive_write_set_format_ustar.c Thu Jan 5 11:44:55 2012 (r229588) @@ -168,7 +168,7 @@ archive_write_set_format_ustar(struct ar /* Basic internal sanity test. */ if (sizeof(template_header) != 512) { - archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal: template_header wrong size: %d should be 512", sizeof(template_header)); + archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "Internal: template_header wrong size: %d should be 512", (int)sizeof(template_header)); return (ARCHIVE_FATAL); } Modified: stable/9/lib/libarchive/config_freebsd.h ============================================================================== --- stable/9/lib/libarchive/config_freebsd.h Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/config_freebsd.h Thu Jan 5 11:44:55 2012 (r229588) @@ -68,6 +68,7 @@ #endif #define HAVE_BSDXML_H 1 +#define HAVE_BZLIB_H 1 #define HAVE_CHFLAGS 1 #define HAVE_CHOWN 1 #define HAVE_DECL_EXTATTR_NAMESPACE_USER 1 Modified: stable/9/lib/libarchive/libarchive-formats.5 ============================================================================== --- stable/9/lib/libarchive/libarchive-formats.5 Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/libarchive-formats.5 Thu Jan 5 11:44:55 2012 (r229588) @@ -65,6 +65,7 @@ Later variants have extended this by eit areas of the header record, extending the header to multiple records, or by storing special entries that modify the interpretation of subsequent entries. +.Pp .Bl -tag -width indent .It Cm gnutar The Modified: stable/9/lib/libarchive/libarchive.3 ============================================================================== --- stable/9/lib/libarchive/libarchive.3 Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/libarchive.3 Thu Jan 5 11:44:55 2012 (r229588) @@ -177,6 +177,8 @@ which provides a slightly more efficient You may prefer to use the higher-level .Fn archive_read_data_skip , which reads and discards the data for this entry, +.Fn archive_read_data_to_buffer , +which reads the data into an in-memory buffer, .Fn archive_read_data_to_file , which copies the data to the provided file descriptor, or .Fn archive_read_extract , Modified: stable/9/lib/libarchive/test/Makefile ============================================================================== --- stable/9/lib/libarchive/test/Makefile Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/test/Makefile Thu Jan 5 11:44:55 2012 (r229588) @@ -52,7 +52,7 @@ TESTS= \ test_read_format_gtar_gz.c \ test_read_format_gtar_lzma.c \ test_read_format_gtar_sparse.c \ - test_read_format_iso_gz.c \ + test_read_format_iso_Z.c \ test_read_format_iso_multi_extent.c \ test_read_format_isorr_rr_moved.c \ test_read_format_isojoliet_bz2.c \ Modified: stable/9/lib/libarchive/test/test_compat_zip.c ============================================================================== --- stable/9/lib/libarchive/test/test_compat_zip.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/lib/libarchive/test/test_compat_zip.c Thu Jan 5 11:44:55 2012 (r229588) @@ -67,7 +67,7 @@ finish: #if ARCHIVE_VERSION_NUMBER < 2000000 archive_read_finish(a); #else - assertEqualInt(ARCHIVE_OK, archive_read_finish(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); #endif } Copied: stable/9/lib/libarchive/test/test_read_format_iso_Z.c (from r228745, head/lib/libarchive/test/test_read_format_iso_Z.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libarchive/test/test_read_format_iso_Z.c Thu Jan 5 11:44:55 2012 (r229588, copy of r228745, head/lib/libarchive/test/test_read_format_iso_Z.c) @@ -0,0 +1,99 @@ +/*- + * Copyright (c) 2003-2007 Tim Kientzle + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "test.h" +__FBSDID("$FreeBSD$"); + +static void +test1(void) +{ + struct archive_entry *ae; + struct archive *a; + const char *name = "test_read_format_iso.iso.Z"; + + extract_reference_file(name); + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_filename(a, name, 512)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_COMPRESS); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); +} + +static +void test2(void) +{ + struct archive_entry *ae; + struct archive *a; + const char *name = "test_read_format_iso_2.iso.Z"; + + extract_reference_file(name); + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_compression_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_filename(a, name, 512)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString(".", archive_entry_pathname(ae)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString("A", archive_entry_pathname(ae)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString("A/B", archive_entry_pathname(ae)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString("C", archive_entry_pathname(ae)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_next_header(a, &ae)); + assertEqualString("C/D", archive_entry_pathname(ae)); + assertEqualIntA(a, ARCHIVE_EOF, + archive_read_next_header(a, &ae)); + assertEqualInt(archive_compression(a), + ARCHIVE_COMPRESSION_COMPRESS); + assertEqualInt(archive_format(a), ARCHIVE_FORMAT_ISO9660); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); +} + +DEFINE_TEST(test_read_format_iso_Z) +{ + test1(); + test2(); +} + + Modified: stable/9/usr.bin/cpio/Makefile ============================================================================== --- stable/9/usr.bin/cpio/Makefile Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/usr.bin/cpio/Makefile Thu Jan 5 11:44:55 2012 (r229588) @@ -3,7 +3,7 @@ .include <bsd.own.mk> PROG= bsdcpio -BSDCPIO_VERSION_STRING=2.8.4 +BSDCPIO_VERSION_STRING=2.8.5 SRCS= cpio.c cmdline.c Modified: stable/9/usr.bin/tar/Makefile ============================================================================== --- stable/9/usr.bin/tar/Makefile Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/usr.bin/tar/Makefile Thu Jan 5 11:44:55 2012 (r229588) @@ -2,7 +2,7 @@ .include <bsd.own.mk> PROG= bsdtar -BSDTAR_VERSION_STRING=2.8.4 +BSDTAR_VERSION_STRING=2.8.5 SRCS= bsdtar.c \ cmdline.c \ getdate.c \ Modified: stable/9/usr.bin/tar/tree.c ============================================================================== --- stable/9/usr.bin/tar/tree.c Thu Jan 5 11:42:34 2012 (r229587) +++ stable/9/usr.bin/tar/tree.c Thu Jan 5 11:44:55 2012 (r229588) @@ -48,6 +48,9 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif +#ifdef HAVE_DIRECT_H +#include <direct.h> +#endif #ifdef HAVE_DIRENT_H #include <dirent.h> #endif @@ -66,6 +69,9 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_UNISTD_H #include <unistd.h> #endif +#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__) +#include <windows.h> +#endif #include "tree.h" @@ -76,27 +82,38 @@ __FBSDID("$FreeBSD$"); */ struct tree_entry { + int depth; struct tree_entry *next; struct tree_entry *parent; char *name; size_t dirname_length; dev_t dev; ino_t ino; + int flags; + /* How to return back to the parent of a symlink. */ #ifdef HAVE_FCHDIR - int fd; + int symlink_parent_fd; #elif defined(_WIN32) && !defined(__CYGWIN__) - char *fullpath; + char *symlink_parent_path; #else #error fchdir function required. #endif - int flags; }; /* Definitions for tree_entry.flags bitmap. */ #define isDir 1 /* This entry is a regular directory. */ #define isDirLink 2 /* This entry is a symbolic link to a directory. */ -#define needsPreVisit 4 /* This entry needs to be previsited. */ -#define needsPostVisit 8 /* This entry needs to be postvisited. */ +#define needsFirstVisit 4 /* This is an initial entry. */ +#define needsDescent 8 /* This entry needs to be previsited. */ +#define needsOpen 16 /* This is a directory that needs to be opened. */ +#define needsAscent 32 /* This entry needs to be postvisited. */ + +/* + * On Windows, "first visit" is handled as a pattern to be handed to + * _findfirst(). This is consistent with Windows conventions that + * file patterns are handled within the application. On Posix, + * "first visit" is just returned to the client. + */ /* * Local data for this package. @@ -104,21 +121,28 @@ struct tree_entry { struct tree { struct tree_entry *stack; struct tree_entry *current; +#if defined(HAVE_WINDOWS_H) && !defined(__CYGWIN__) + HANDLE d; + BY_HANDLE_FILE_INFORMATION fileInfo; +#define INVALID_DIR_HANDLE INVALID_HANDLE_VALUE + WIN32_FIND_DATA _findData; + WIN32_FIND_DATA *findData; +#else DIR *d; -#ifdef HAVE_FCHDIR - int initialDirFd; -#elif defined(_WIN32) && !defined(__CYGWIN__) - char *initialDir; +#define INVALID_DIR_HANDLE NULL + struct dirent *de; #endif int flags; int visit_type; int tree_errno; /* Error code from last failed operation. */ + /* Dynamically-sized buffer for holding path */ char *buff; - const char *basename; size_t buff_length; - size_t path_length; - size_t dirname_length; + + const char *basename; /* Last path element */ + size_t dirname_length; /* Leading dir length */ + size_t path_length; /* Total path length */ int depth; int openCount; @@ -129,10 +153,17 @@ struct tree { }; /* Definitions for tree.flags bitmap. */ -#define needsReturn 8 /* Marks first entry as not having been returned yet. */ -#define hasStat 16 /* The st entry is set. */ -#define hasLstat 32 /* The lst entry is set. */ +#define hasStat 16 /* The st entry is valid. */ +#define hasLstat 32 /* The lst entry is valid. */ +#define hasFileInfo 64 /* The Windows fileInfo entry is valid. */ +#if defined(_WIN32) && !defined(__CYGWIN__) +static int +tree_dir_next_windows(struct tree *t, const char *pattern); +#else +static int +tree_dir_next_posix(struct tree *t); +#endif #ifdef HAVE_DIRENT_D_NAMLEN /* BSD extension; avoids need for a strlen() call. */ @@ -141,25 +172,32 @@ struct tree { #define D_NAMELEN(dp) (strlen((dp)->d_name)) #endif -#if 0 #include <stdio.h> void tree_dump(struct tree *t, FILE *out) { + char buff[300]; struct tree_entry *te; fprintf(out, "\tdepth: %d\n", t->depth); fprintf(out, "\tbuff: %s\n", t->buff); - fprintf(out, "\tpwd: "); fflush(stdout); system("pwd"); - fprintf(out, "\taccess: %s\n", t->basename); + fprintf(out, "\tpwd: %s\n", getcwd(buff, sizeof(buff))); + fprintf(out, "\tbasename: %s\n", t->basename); fprintf(out, "\tstack:\n"); for (te = t->stack; te != NULL; te = te->next) { - fprintf(out, "\t\tte->name: %s%s%s\n", te->name, - te->flags & needsPreVisit ? "" : " *", - t->current == te ? " (current)" : ""); + fprintf(out, "\t\t%s%d:\"%s\" %s%s%s%s%s%s\n", + t->current == te ? "*" : " ", + te->depth, + te->name, + te->flags & needsFirstVisit ? "V" : "", + te->flags & needsDescent ? "D" : "", + te->flags & needsOpen ? "O" : "", + te->flags & needsAscent ? "A" : "", + te->flags & isDirLink ? "L" : "", + (t->current == te && t->d) ? "+" : "" + ); } } -#endif /* * Add a directory path to the current stack. @@ -172,24 +210,29 @@ tree_push(struct tree *t, const char *pa te = malloc(sizeof(*te)); memset(te, 0, sizeof(*te)); te->next = t->stack; + te->parent = t->current; + if (te->parent) + te->depth = te->parent->depth + 1; t->stack = te; #ifdef HAVE_FCHDIR - te->fd = -1; + te->symlink_parent_fd = -1; + te->name = strdup(path); #elif defined(_WIN32) && !defined(__CYGWIN__) - te->fullpath = NULL; -#endif + te->symlink_parent_path = NULL; te->name = strdup(path); - te->flags = needsPreVisit | needsPostVisit; +#endif + te->flags = needsDescent | needsOpen | needsAscent; te->dirname_length = t->dirname_length; } /* - * Append a name to the current path. + * Append a name to the current dir path. */ static void tree_append(struct tree *t, const char *name, size_t name_length) { char *p; + size_t size_needed; if (t->buff != NULL) t->buff[t->dirname_length] = '\0'; @@ -198,12 +241,16 @@ tree_append(struct tree *t, const char * name_length--; /* Resize pathname buffer as needed. */ - while (name_length + 1 + t->dirname_length >= t->buff_length) { - t->buff_length *= 2; + size_needed = name_length + 1 + t->dirname_length; + if (t->buff_length < size_needed) { if (t->buff_length < 1024) t->buff_length = 1024; + while (t->buff_length < size_needed) + t->buff_length *= 2; t->buff = realloc(t->buff, t->buff_length); } + if (t->buff == NULL) + abort(); p = t->buff + t->dirname_length; t->path_length = t->dirname_length + name_length; /* Add a separating '/' if it's needed. */ @@ -211,7 +258,11 @@ tree_append(struct tree *t, const char * *p++ = '/'; t->path_length ++; } +#if HAVE_STRNCPY_S + strncpy_s(p, t->buff_length - (p - t->buff), name, name_length); +#else strncpy(p, name, name_length); +#endif p[name_length] = '\0'; t->basename = p; } @@ -222,24 +273,55 @@ tree_append(struct tree *t, const char * struct tree * tree_open(const char *path) { +#ifdef HAVE_FCHDIR struct tree *t; t = malloc(sizeof(*t)); memset(t, 0, sizeof(*t)); - tree_append(t, path, strlen(path)); -#ifdef HAVE_FCHDIR - t->initialDirFd = open(".", O_RDONLY); + /* First item is set up a lot like a symlink traversal. */ + tree_push(t, path); + t->stack->flags = needsFirstVisit | isDirLink | needsAscent; + t->stack->symlink_parent_fd = open(".", O_RDONLY); + t->openCount++; + t->d = INVALID_DIR_HANDLE; + return (t); #elif defined(_WIN32) && !defined(__CYGWIN__) - t->initialDir = getcwd(NULL, 0); -#endif - /* - * During most of the traversal, items are set up and then - * returned immediately from tree_next(). That doesn't work - * for the very first entry, so we set a flag for this special - * case. - */ - t->flags = needsReturn; + struct tree *t; + char *cwd = _getcwd(NULL, 0); + char *pathname = strdup(path), *p, *base; + + if (pathname == NULL) + abort(); + for (p = pathname; *p != '\0'; ++p) { + if (*p == '\\') + *p = '/'; + } + base = pathname; + + t = malloc(sizeof(*t)); + memset(t, 0, sizeof(*t)); + /* First item is set up a lot like a symlink traversal. */ + /* printf("Looking for wildcard in %s\n", path); */ + /* TODO: wildcard detection here screws up on \\?\c:\ UNC names */ + if (strchr(base, '*') || strchr(base, '?')) { + // It has a wildcard in it... + // Separate the last element. + p = strrchr(base, '/'); + if (p != NULL) { + *p = '\0'; + chdir(base); + tree_append(t, base, p - base); + t->dirname_length = t->path_length; + base = p + 1; + } + } + tree_push(t, base); + free(pathname); + t->stack->flags = needsFirstVisit | isDirLink | needsAscent; + t->stack->symlink_parent_path = cwd; + t->d = INVALID_DIR_HANDLE; return (t); +#endif } /* @@ -255,22 +337,26 @@ tree_ascend(struct tree *t) t->depth--; if (te->flags & isDirLink) { #ifdef HAVE_FCHDIR - if (fchdir(te->fd) != 0) { + if (fchdir(te->symlink_parent_fd) != 0) { t->tree_errno = errno; r = TREE_ERROR_FATAL; } - close(te->fd); + close(te->symlink_parent_fd); #elif defined(_WIN32) && !defined(__CYGWIN__) - if (chdir(te->fullpath) != 0) { + if (SetCurrentDirectory(te->symlink_parent_path) == 0) { t->tree_errno = errno; r = TREE_ERROR_FATAL; } - free(te->fullpath); - te->fullpath = NULL; + free(te->symlink_parent_path); + te->symlink_parent_path = NULL; #endif t->openCount--; } else { +#if defined(_WIN32) && !defined(__CYGWIN__) + if (SetCurrentDirectory("..") == 0) { +#else if (chdir("..") != 0) { +#endif t->tree_errno = errno; r = TREE_ERROR_FATAL; } @@ -286,16 +372,18 @@ tree_pop(struct tree *t) { *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** _______________________________________________ svn-src-all@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"