diff options
author | Martin Matuska <mm@FreeBSD.org> | 2022-12-13 19:21:13 +0000 |
---|---|---|
committer | Martin Matuska <mm@FreeBSD.org> | 2022-12-13 19:21:13 +0000 |
commit | bd5e624a861433dee76fe00a8acedc9564425332 (patch) | |
tree | 97d4161e1e560abd387d9f15b214b39da6dc806e /contrib/libarchive | |
parent | 8d0ed56646f03c922c1ff76b07413de3f0b9d062 (diff) | |
parent | b5a00e61e90d12782d023f98d9bf9bebf65733ed (diff) | |
download | src-bd5e624a861433dee76fe00a8acedc9564425332.tar.gz src-bd5e624a861433dee76fe00a8acedc9564425332.zip |
libarchive: merge from vendor branch
Libarchive 3.6.2
Important bug fixes:
rar5 reader: fix possible garbled output with bsdtar -O (#1745)
mtree reader: support reading mtree files with tabs (#1783)
various small fixes for issues found by CodeQL
MFC after: 2 weeks
PR: 286306 (exp-run)
Diffstat (limited to 'contrib/libarchive')
63 files changed, 608 insertions, 178 deletions
diff --git a/contrib/libarchive/NEWS b/contrib/libarchive/NEWS index bf0515f34d8c..d6324487691b 100644 --- a/contrib/libarchive/NEWS +++ b/contrib/libarchive/NEWS @@ -1,3 +1,5 @@ +Wed 07, 2022: libarchive 3.6.2 released + Apr 08, 2022: libarchive 3.6.1 released Feb 09, 2022: libarchive 3.6.0 released diff --git a/contrib/libarchive/README.md b/contrib/libarchive/README.md index d5ef70c2191d..404076237871 100644 --- a/contrib/libarchive/README.md +++ b/contrib/libarchive/README.md @@ -37,6 +37,7 @@ The top-level directory contains the following information files: * **configure** - configuration script, see INSTALL for details. If your copy of the source lacks a `configure` script, you can try to construct it by running the script in `build/autogen.sh` (or use `cmake`). The following files in the top-level directory are used by the 'configure' script: + * `Makefile.am`, `aclocal.m4`, `configure.ac` - used to build this distribution, only needed by maintainers * `Makefile.in`, `config.h.in` - templates used by configure script @@ -71,6 +72,7 @@ know about any errors or omissions you find. ## Supported Formats Currently, the library automatically detects and reads the following formats: + * Old V7 tar archives * POSIX ustar * GNU tar format (including GNU long filenames, long link names, and sparse files) @@ -92,6 +94,7 @@ Currently, the library automatically detects and reads the following formats: * XAR archives The library also detects and handles any of the following before evaluating the archive: + * uuencoded files * files with RPM wrapper * gzip compression @@ -103,6 +106,7 @@ The library also detects and handles any of the following before evaluating the * zstandard compression The library can create archives in any of the following formats: + * POSIX ustar * POSIX pax interchange format * "restricted" pax format, which will create ustar archives except for @@ -122,6 +126,7 @@ The library can create archives in any of the following formats: * XAR archives When creating archives, the result can be filtered with any of the following: + * uuencode * gzip compression * bzip2 compression diff --git a/contrib/libarchive/cpio/test/test_option_t.c b/contrib/libarchive/cpio/test/test_option_t.c index eaa73fa3a016..0f2dda27cc20 100644 --- a/contrib/libarchive/cpio/test/test_option_t.c +++ b/contrib/libarchive/cpio/test/test_option_t.c @@ -36,6 +36,14 @@ DEFINE_TEST(test_option_t) time_t mtime; char date[32]; char date2[32]; + struct tm *tmptr; +#if defined(HAVE_LOCALTIME_R) || defined(HAVE__LOCALTIME64_S) + struct tm tmbuf; +#endif +#if defined(HAVE__LOCALTIME64_S) + errno_t terr; + __time64_t tmptime; +#endif /* List reference archive, make sure the TOC is correct. */ extract_reference_file("test_option_t.cpio"); @@ -87,11 +95,23 @@ DEFINE_TEST(test_option_t) #ifdef HAVE_LOCALE_H setlocale(LC_ALL, ""); #endif +#if defined(HAVE_LOCALTIME_R) + tmptr = localtime_r(&mtime, &tmbuf); +#elif defined(HAVE__LOCALTIME64_S) + tmptime = mtime; + terr = _localtime64_s(&tmbuf, &tmptime); + if (terr) + tmptr = NULL; + else + tmptr = &tmbuf; +#else + tmptr = localtime(&mtime); +#endif #if defined(_WIN32) && !defined(__CYGWIN__) - strftime(date2, sizeof(date2)-1, "%b %d %Y", localtime(&mtime)); + strftime(date2, sizeof(date2)-1, "%b %d %Y", tmptr); _snprintf(date, sizeof(date)-1, "%12.12s file", date2); #else - strftime(date2, sizeof(date2)-1, "%b %e %Y", localtime(&mtime)); + strftime(date2, sizeof(date2)-1, "%b %e %Y", tmptr); snprintf(date, sizeof(date)-1, "%12.12s file", date2); #endif assertEqualMem(p + 42, date, strlen(date)); diff --git a/contrib/libarchive/libarchive/archive.h b/contrib/libarchive/libarchive/archive.h index ee1a02f4de01..5fa56de6c9fd 100644 --- a/contrib/libarchive/libarchive/archive.h +++ b/contrib/libarchive/libarchive/archive.h @@ -36,7 +36,7 @@ * assert that ARCHIVE_VERSION_NUMBER >= 2012108. */ /* Note: Compiler will complain if this does not match archive_entry.h! */ -#define ARCHIVE_VERSION_NUMBER 3006001 +#define ARCHIVE_VERSION_NUMBER 3006002 #include <sys/stat.h> #include <stddef.h> /* for wchar_t */ @@ -120,6 +120,8 @@ typedef ssize_t la_ssize_t; # define __LA_DECL __declspec(dllimport) # endif # endif +#elif defined __LIBARCHIVE_ENABLE_VISIBILITY +# define __LA_DECL __attribute__((visibility("default"))) #else /* Static libraries or non-Windows needs no special declaration. */ # define __LA_DECL @@ -155,7 +157,7 @@ __LA_DECL int archive_version_number(void); /* * Textual name/version of the library, useful for version displays. */ -#define ARCHIVE_VERSION_ONLY_STRING "3.6.1" +#define ARCHIVE_VERSION_ONLY_STRING "3.6.2" #define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING __LA_DECL const char * archive_version_string(void); diff --git a/contrib/libarchive/libarchive/archive_digest.c b/contrib/libarchive/libarchive/archive_digest.c index a7bd5f0286a4..3361b19ada82 100644 --- a/contrib/libarchive/libarchive/archive_digest.c +++ b/contrib/libarchive/libarchive/archive_digest.c @@ -49,16 +49,16 @@ * Initialize a Message digest. */ static int -win_crypto_init(Digest_CTX *ctx, ALG_ID algId) +win_crypto_init(Digest_CTX *ctx, DWORD prov, ALG_ID algId) { ctx->valid = 0; if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL, - PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { + prov, CRYPT_VERIFYCONTEXT)) { if (GetLastError() != (DWORD)NTE_BAD_KEYSET) return (ARCHIVE_FAILED); if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL, - PROV_RSA_FULL, CRYPT_NEWKEYSET)) + prov, CRYPT_NEWKEYSET)) return (ARCHIVE_FAILED); } @@ -276,7 +276,7 @@ __archive_md5final(archive_md5_ctx *ctx, void *md) static int __archive_md5init(archive_md5_ctx *ctx) { - return (win_crypto_init(ctx, CALG_MD5)); + return (win_crypto_init(ctx, PROV_RSA_FULL, CALG_MD5)); } static int @@ -659,7 +659,7 @@ __archive_sha1final(archive_sha1_ctx *ctx, void *md) static int __archive_sha1init(archive_sha1_ctx *ctx) { - return (win_crypto_init(ctx, CALG_SHA1)); + return (win_crypto_init(ctx, PROV_RSA_FULL, CALG_SHA1)); } static int @@ -919,7 +919,7 @@ __archive_sha256final(archive_sha256_ctx *ctx, void *md) static int __archive_sha256init(archive_sha256_ctx *ctx) { - return (win_crypto_init(ctx, CALG_SHA_256)); + return (win_crypto_init(ctx, PROV_RSA_AES, CALG_SHA_256)); } static int @@ -1155,7 +1155,7 @@ __archive_sha384final(archive_sha384_ctx *ctx, void *md) static int __archive_sha384init(archive_sha384_ctx *ctx) { - return (win_crypto_init(ctx, CALG_SHA_384)); + return (win_crypto_init(ctx, PROV_RSA_AES, CALG_SHA_384)); } static int @@ -1415,7 +1415,7 @@ __archive_sha512final(archive_sha512_ctx *ctx, void *md) static int __archive_sha512init(archive_sha512_ctx *ctx) { - return (win_crypto_init(ctx, CALG_SHA_512)); + return (win_crypto_init(ctx, PROV_RSA_AES, CALG_SHA_512)); } static int diff --git a/contrib/libarchive/libarchive/archive_entry.c b/contrib/libarchive/libarchive/archive_entry.c index ba536dcdffe2..819fe451aa4b 100644 --- a/contrib/libarchive/libarchive/archive_entry.c +++ b/contrib/libarchive/libarchive/archive_entry.c @@ -568,6 +568,13 @@ archive_entry_nlink(struct archive_entry *entry) return (entry->ae_stat.aest_nlink); } +/* Instead, our caller could have chosen a specific encoding + * (archive_mstring_get_mbs, archive_mstring_get_utf8, + * archive_mstring_get_wcs). So we should try multiple + * encodings. Try mbs first because of history, even though + * utf8 might be better for pathname portability. + * Also omit wcs because of type mismatch (char * versus wchar *) + */ const char * archive_entry_pathname(struct archive_entry *entry) { @@ -575,6 +582,13 @@ archive_entry_pathname(struct archive_entry *entry) if (archive_mstring_get_mbs( entry->archive, &entry->ae_pathname, &p) == 0) return (p); +#if HAVE_EILSEQ /*{*/ + if (errno == EILSEQ) { + if (archive_mstring_get_utf8( + entry->archive, &entry->ae_pathname, &p) == 0) + return (p); + } +#endif /*}*/ if (errno == ENOMEM) __archive_errx(1, "No memory"); return (NULL); diff --git a/contrib/libarchive/libarchive/archive_entry.h b/contrib/libarchive/libarchive/archive_entry.h index 461866a5a6a2..ff64a4712a56 100644 --- a/contrib/libarchive/libarchive/archive_entry.h +++ b/contrib/libarchive/libarchive/archive_entry.h @@ -30,7 +30,7 @@ #define ARCHIVE_ENTRY_H_INCLUDED /* Note: Compiler will complain if this does not match archive.h! */ -#define ARCHIVE_VERSION_NUMBER 3006001 +#define ARCHIVE_VERSION_NUMBER 3006002 /* * Note: archive_entry.h is for use outside of libarchive; the @@ -122,6 +122,8 @@ typedef ssize_t la_ssize_t; # define __LA_DECL __declspec(dllimport) # endif # endif +#elif defined __LIBARCHIVE_ENABLE_VISIBILITY +# define __LA_DECL __attribute__((visibility("default"))) #else /* Static libraries on all platforms and shared libraries on non-Windows. */ # define __LA_DECL diff --git a/contrib/libarchive/libarchive/archive_hmac.c b/contrib/libarchive/libarchive/archive_hmac.c index 2a9d04c8d8f1..012fe1596211 100644 --- a/contrib/libarchive/libarchive/archive_hmac.c +++ b/contrib/libarchive/libarchive/archive_hmac.c @@ -230,10 +230,23 @@ __hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx) static int __hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + OSSL_PARAM params[2]; + + EVP_MAC *mac = EVP_MAC_fetch(NULL, "HMAC", NULL); + *ctx = EVP_MAC_CTX_new(mac); + if (*ctx == NULL) + return -1; + EVP_MAC_free(mac); + params[0] = OSSL_PARAM_construct_utf8_string("digest", "SHA1", 0); + params[1] = OSSL_PARAM_construct_end(); + EVP_MAC_init(*ctx, key, key_len, params); +#else *ctx = HMAC_CTX_new(); if (*ctx == NULL) return -1; HMAC_Init_ex(*ctx, key, key_len, EVP_sha1(), NULL); +#endif return 0; } @@ -241,22 +254,38 @@ static void __hmac_sha1_update(archive_hmac_sha1_ctx *ctx, const uint8_t *data, size_t data_len) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + EVP_MAC_update(*ctx, data, data_len); +#else HMAC_Update(*ctx, data, data_len); +#endif } static void __hmac_sha1_final(archive_hmac_sha1_ctx *ctx, uint8_t *out, size_t *out_len) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + size_t len = *out_len; +#else unsigned int len = (unsigned int)*out_len; +#endif +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + EVP_MAC_final(*ctx, out, &len, *out_len); +#else HMAC_Final(*ctx, out, &len); +#endif *out_len = len; } static void __hmac_sha1_cleanup(archive_hmac_sha1_ctx *ctx) { +#if OPENSSL_VERSION_NUMBER >= 0x30000000L + EVP_MAC_CTX_free(*ctx); +#else HMAC_CTX_free(*ctx); +#endif *ctx = NULL; } diff --git a/contrib/libarchive/libarchive/archive_hmac_private.h b/contrib/libarchive/libarchive/archive_hmac_private.h index 13a67d4955a5..50044a045e37 100644 --- a/contrib/libarchive/libarchive/archive_hmac_private.h +++ b/contrib/libarchive/libarchive/archive_hmac_private.h @@ -74,9 +74,16 @@ typedef mbedtls_md_context_t archive_hmac_sha1_ctx; typedef struct hmac_sha1_ctx archive_hmac_sha1_ctx; #elif defined(HAVE_LIBCRYPTO) +#include <openssl/opensslv.h> +#include <openssl/hmac.h> +#if OPENSSL_VERSION_NUMBER >= 0x30000000L +typedef EVP_MAC_CTX *archive_hmac_sha1_ctx; + +#else #include "archive_openssl_hmac_private.h" typedef HMAC_CTX* archive_hmac_sha1_ctx; +#endif #else diff --git a/contrib/libarchive/libarchive/archive_platform.h b/contrib/libarchive/libarchive/archive_platform.h index 668db4e81b02..bfd1c387eeba 100644 --- a/contrib/libarchive/libarchive/archive_platform.h +++ b/contrib/libarchive/libarchive/archive_platform.h @@ -195,8 +195,9 @@ /* * glibc 2.24 deprecates readdir_r + * bionic c deprecates readdir_r too */ -#if defined(HAVE_READDIR_R) && (!defined(__GLIBC__) || !defined(__GLIBC_MINOR__) || __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 24)) +#if defined(HAVE_READDIR_R) && (!defined(__GLIBC__) || !defined(__GLIBC_MINOR__) || __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 24)) && (!defined(__ANDROID__)) #define USE_READDIR_R 1 #else #undef USE_READDIR_R diff --git a/contrib/libarchive/libarchive/archive_read_disk_posix.c b/contrib/libarchive/libarchive/archive_read_disk_posix.c index 2b39e672b49c..5a94ec5d4399 100644 --- a/contrib/libarchive/libarchive/archive_read_disk_posix.c +++ b/contrib/libarchive/libarchive/archive_read_disk_posix.c @@ -34,9 +34,6 @@ __FBSDID("$FreeBSD$"); #ifdef HAVE_SYS_PARAM_H #include <sys/param.h> #endif -#ifdef HAVE_SYS_MOUNT_H -#include <sys/mount.h> -#endif #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif @@ -54,6 +51,8 @@ __FBSDID("$FreeBSD$"); #endif #ifdef HAVE_LINUX_FS_H #include <linux/fs.h> +#elif HAVE_SYS_MOUNT_H +#include <sys/mount.h> #endif /* * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h. @@ -2103,6 +2102,8 @@ tree_push(struct tree *t, const char *path, int filesystem_id, struct tree_entry *te; te = calloc(1, sizeof(*te)); + if (te == NULL) + __archive_errx(1, "Out of memory"); te->next = t->stack; te->parent = t->current; if (te->parent) diff --git a/contrib/libarchive/libarchive/archive_read_support_filter_lz4.c b/contrib/libarchive/libarchive/archive_read_support_filter_lz4.c index ae0b08003f80..1e99542d7b7b 100644 --- a/contrib/libarchive/libarchive/archive_read_support_filter_lz4.c +++ b/contrib/libarchive/libarchive/archive_read_support_filter_lz4.c @@ -450,7 +450,9 @@ lz4_filter_read_descriptor(struct archive_read_filter *self) chsum = (chsum >> 8) & 0xff; chsum_verifier = read_buf[descriptor_bytes-1] & 0xff; if (chsum != chsum_verifier) +#ifndef DONT_FAIL_ON_CRC_ERROR goto malformed_error; +#endif __archive_read_filter_consume(self->upstream, descriptor_bytes); @@ -521,7 +523,9 @@ lz4_filter_read_data_block(struct archive_read_filter *self, const void **p) unsigned int chsum_block = archive_le32dec(read_buf + 4 + compressed_size); if (chsum != chsum_block) +#ifndef DONT_FAIL_ON_CRC_ERROR goto malformed_error; +#endif } @@ -652,10 +656,12 @@ lz4_filter_read_default_stream(struct archive_read_filter *self, const void **p) state->xxh32_state); state->xxh32_state = NULL; if (checksum != checksum_stream) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, "lz4 stream checksum error"); return (ARCHIVE_FATAL); +#endif } } else if (ret > 0) __archive_xxhash.XXH32_update(state->xxh32_state, diff --git a/contrib/libarchive/libarchive/archive_read_support_filter_lzop.c b/contrib/libarchive/libarchive/archive_read_support_filter_lzop.c index afd2d4d0c49a..4ebdd3bf3eb1 100644 --- a/contrib/libarchive/libarchive/archive_read_support_filter_lzop.c +++ b/contrib/libarchive/libarchive/archive_read_support_filter_lzop.c @@ -283,7 +283,9 @@ consume_header(struct archive_read_filter *self) else checksum = adler32(adler32(0, NULL, 0), p, len); if (archive_be32dec(p + len) != checksum) +#ifndef DONT_FAIL_ON_CRC_ERROR goto corrupted; +#endif __archive_read_filter_consume(self->upstream, len + 4); if (flags & EXTRA_FIELD) { /* Skip extra field */ diff --git a/contrib/libarchive/libarchive/archive_read_support_filter_xz.c b/contrib/libarchive/libarchive/archive_read_support_filter_xz.c index 32ae0be92e0e..e313d39c0cf2 100644 --- a/contrib/libarchive/libarchive/archive_read_support_filter_xz.c +++ b/contrib/libarchive/libarchive/archive_read_support_filter_xz.c @@ -612,9 +612,11 @@ lzip_tail(struct archive_read_filter *self) /* Check the crc32 value of the uncompressed data of the current * member */ if (state->crc32 != archive_le32dec(f)) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC, "Lzip: CRC32 error"); return (ARCHIVE_FAILED); +#endif } /* Check the uncompressed size of the current member */ diff --git a/contrib/libarchive/libarchive/archive_read_support_format_7zip.c b/contrib/libarchive/libarchive/archive_read_support_format_7zip.c index 564ba514a4b1..0ba4bee358b2 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_7zip.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_7zip.c @@ -776,7 +776,7 @@ archive_read_format_7zip_read_header(struct archive_read *a, } /* Set up a more descriptive format name. */ - sprintf(zip->format_name, "7-Zip"); + snprintf(zip->format_name, sizeof(zip->format_name), "7-Zip"); a->archive.archive_format_name = zip->format_name; return (ret); @@ -2857,8 +2857,10 @@ slurp_central_directory(struct archive_read *a, struct _7zip *zip, /* CRC check. */ if (crc32(0, (const unsigned char *)p + 12, 20) != archive_le32dec(p + 8)) { +#ifdef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, -1, "Header CRC error"); return (ARCHIVE_FATAL); +#endif } next_header_offset = archive_le64dec(p + 12); @@ -2908,8 +2910,10 @@ slurp_central_directory(struct archive_read *a, struct _7zip *zip, /* Check the EncodedHeader CRC.*/ if (r == 0 && zip->header_crc32 != next_header_crc) { archive_set_error(&a->archive, -1, +#ifndef DONT_FAIL_ON_CRC_ERROR "Damaged 7-Zip archive"); r = -1; +#endif } if (r == 0) { if (zip->si.ci.folders[0].digest_defined) @@ -2960,9 +2964,11 @@ slurp_central_directory(struct archive_read *a, struct _7zip *zip, /* Check the Header CRC.*/ if (check_header_crc && zip->header_crc32 != next_header_crc) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, -1, "Malformed 7-Zip archive"); return (ARCHIVE_FATAL); +#endif } break; default: diff --git a/contrib/libarchive/libarchive/archive_read_support_format_cab.c b/contrib/libarchive/libarchive/archive_read_support_format_cab.c index 950f3d254de6..4d5029b1bd2e 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_cab.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_cab.c @@ -996,7 +996,7 @@ archive_read_format_cab_read_header(struct archive_read *a, cab->end_of_entry_cleanup = cab->end_of_entry = 1; /* Set up a more descriptive format name. */ - sprintf(cab->format_name, "CAB %d.%d (%s)", + snprintf(cab->format_name, sizeof(cab->format_name), "CAB %d.%d (%s)", hd->major, hd->minor, cab->entry_cffolder->compname); a->archive.archive_format_name = cab->format_name; @@ -1134,7 +1134,7 @@ cab_checksum_update(struct archive_read *a, size_t bytes) } if (sumbytes) { int odd = sumbytes & 3; - if (sumbytes - odd > 0) + if ((int)(sumbytes - odd) > 0) cfdata->sum_calculated = cab_checksum_cfdata_4( p, sumbytes - odd, cfdata->sum_calculated); if (odd) @@ -1171,12 +1171,14 @@ cab_checksum_finish(struct archive_read *a) cfdata->sum_calculated = cab_checksum_cfdata( cfdata->memimage + CFDATA_cbData, l, cfdata->sum_calculated); if (cfdata->sum_calculated != cfdata->sum) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Checksum error CFDATA[%d] %" PRIx32 ":%" PRIx32 " in %d bytes", cab->entry_cffolder->cfdata_index -1, cfdata->sum, cfdata->sum_calculated, cfdata->compressed_size); return (ARCHIVE_FAILED); +#endif } return (ARCHIVE_OK); } diff --git a/contrib/libarchive/libarchive/archive_read_support_format_iso9660.c b/contrib/libarchive/libarchive/archive_read_support_format_iso9660.c index 15ded7c561e5..390ab84f43e3 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_iso9660.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_iso9660.c @@ -1757,7 +1757,7 @@ parse_file_info(struct archive_read *a, struct file_info *parent, size_t name_len; const unsigned char *rr_start, *rr_end; const unsigned char *p; - size_t dr_len; + size_t dr_len = 0; uint64_t fsize, offset; int32_t location; int flags; diff --git a/contrib/libarchive/libarchive/archive_read_support_format_lha.c b/contrib/libarchive/libarchive/archive_read_support_format_lha.c index bff0f01f41cf..bcfd42e1d920 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_lha.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_lha.c @@ -739,7 +739,7 @@ archive_read_format_lha_read_header(struct archive_read *a, if (lha->directory || lha->compsize == 0) lha->end_of_entry = 1; - sprintf(lha->format_name, "lha -%c%c%c-", + snprintf(lha->format_name, sizeof(lha->format_name), "lha -%c%c%c-", lha->method[0], lha->method[1], lha->method[2]); a->archive.archive_format_name = lha->format_name; @@ -1039,9 +1039,11 @@ lha_read_file_header_2(struct archive_read *a, struct lha *lha) } if (header_crc != lha->header_crc) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "LHa header CRC error"); return (ARCHIVE_FATAL); +#endif } return (err); } @@ -1107,9 +1109,11 @@ lha_read_file_header_3(struct archive_read *a, struct lha *lha) return (err); if (header_crc != lha->header_crc) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "LHa header CRC error"); return (ARCHIVE_FATAL); +#endif } return (err); invalid: diff --git a/contrib/libarchive/libarchive/archive_read_support_format_mtree.c b/contrib/libarchive/libarchive/archive_read_support_format_mtree.c index 96eb133ed361..33a804501693 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_mtree.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_mtree.c @@ -994,9 +994,11 @@ process_add_entry(struct archive_read *a, struct mtree *mtree, struct mtree_entry *alt; alt = (struct mtree_entry *)__archive_rb_tree_find_node( &mtree->rbtree, entry->name); - while (alt->next_dup) - alt = alt->next_dup; - alt->next_dup = entry; + if (alt != NULL) { + while (alt->next_dup) + alt = alt->next_dup; + alt->next_dup = entry; + } } } @@ -1071,7 +1073,7 @@ read_mtree(struct archive_read *a, struct mtree *mtree) continue; /* Non-printable characters are not allowed */ for (s = p;s < p + len - 1; s++) { - if (!isprint((unsigned char)*s)) { + if (!isprint((unsigned char)*s) && *s != '\t') { r = ARCHIVE_FATAL; break; } @@ -1250,9 +1252,17 @@ parse_file(struct archive_read *a, struct archive_entry *entry, archive_entry_filetype(entry) == AE_IFDIR) { mtree->fd = open(path, O_RDONLY | O_BINARY | O_CLOEXEC); __archive_ensure_cloexec_flag(mtree->fd); - if (mtree->fd == -1 && - (errno != ENOENT || - archive_strlen(&mtree->contents_name) > 0)) { + if (mtree->fd == -1 && ( +#if defined(_WIN32) && !defined(__CYGWIN__) + /* + * On Windows, attempting to open a file with an + * invalid name result in EINVAL (Error 22) + */ + (errno != ENOENT && errno != EINVAL) +#else + errno != ENOENT +#endif + || archive_strlen(&mtree->contents_name) > 0)) { archive_set_error(&a->archive, errno, "Can't open %s", path); r = ARCHIVE_WARN; diff --git a/contrib/libarchive/libarchive/archive_read_support_format_rar.c b/contrib/libarchive/libarchive/archive_read_support_format_rar.c index f9cbe2a8810d..793e8e985214 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_rar.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_rar.c @@ -1007,9 +1007,11 @@ archive_read_format_rar_read_header(struct archive_read *a, crc32_val = crc32(0, (const unsigned char *)p + 2, (unsigned)skip - 2); if ((crc32_val & 0xffff) != archive_le16dec(p)) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Header CRC error"); return (ARCHIVE_FATAL); +#endif } __archive_read_consume(a, skip); break; @@ -1065,9 +1067,11 @@ archive_read_format_rar_read_header(struct archive_read *a, skip -= to_read; } if ((crc32_val & 0xffff) != crc32_expected) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Header CRC error"); return (ARCHIVE_FATAL); +#endif } if (head_type == ENDARC_HEAD) return (ARCHIVE_EOF); @@ -1432,9 +1436,11 @@ read_header(struct archive_read *a, struct archive_entry *entry, /* File Header CRC check. */ crc32_val = crc32(crc32_val, h, (unsigned)(header_size - 7)); if ((crc32_val & 0xffff) != archive_le16dec(rar_header.crc)) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Header CRC error"); return (ARCHIVE_FATAL); +#endif } /* If no CRC error, Go on parsing File Header. */ p = h; @@ -1952,9 +1958,11 @@ read_data_stored(struct archive_read *a, const void **buff, size_t *size, *size = 0; *offset = rar->offset; if (rar->file_crc != rar->crc_calculated) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "File CRC error"); return (ARCHIVE_FATAL); +#endif } rar->entry_eof = 1; return (ARCHIVE_EOF); @@ -2045,9 +2053,11 @@ read_data_compressed(struct archive_read *a, const void **buff, size_t *size, *size = 0; *offset = rar->offset; if (rar->file_crc != rar->crc_calculated) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "File CRC error"); return (ARCHIVE_FATAL); +#endif } rar->entry_eof = 1; return (ARCHIVE_EOF); diff --git a/contrib/libarchive/libarchive/archive_read_support_format_rar5.c b/contrib/libarchive/libarchive/archive_read_support_format_rar5.c index a3cfa72e77c8..38979cbe91a8 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_rar5.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_rar5.c @@ -2821,11 +2821,13 @@ static int parse_block_header(struct archive_read* a, const uint8_t* p, ^ (uint8_t) (*block_size >> 16); if(calculated_cksum != hdr->block_cksum) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&a->archive, ARCHIVE_ERRNO_FILE_FORMAT, "Block checksum error: got 0x%x, expected 0x%x", hdr->block_cksum, calculated_cksum); return ARCHIVE_FATAL; +#endif } return ARCHIVE_OK; @@ -3911,6 +3913,13 @@ static int do_unpack(struct archive_read* a, struct rar5* rar, case GOOD: /* fallthrough */ case BEST: + /* No data is returned here. But because a sparse-file aware + * caller (like archive_read_data_into_fd) may treat zero-size + * as a sparse file block, we need to update the offset + * accordingly. At this point the decoder doesn't have any + * pending uncompressed data blocks, so the current position in + * the output file should be last_write_ptr. */ + if (offset) *offset = rar->cstate.last_write_ptr; return uncompress_file(a); default: archive_set_error(&a->archive, diff --git a/contrib/libarchive/libarchive/archive_read_support_format_tar.c b/contrib/libarchive/libarchive/archive_read_support_format_tar.c index 73bf323baf2f..892d9c7d26c9 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_tar.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_tar.c @@ -407,14 +407,13 @@ archive_read_format_tar_bid(struct archive_read *a, int best_bid) /* * Check format of mode/uid/gid/mtime/size/rdevmajor/rdevminor fields. */ - if (bid > 0 && ( - validate_number_field(header->mode, sizeof(header->mode)) == 0 + if (validate_number_field(header->mode, sizeof(header->mode)) == 0 || validate_number_field(header->uid, sizeof(header->uid)) == 0 || validate_number_field(header->gid, sizeof(header->gid)) == 0 || validate_number_field(header->mtime, sizeof(header->mtime)) == 0 || validate_number_field(header->size, sizeof(header->size)) == 0 || validate_number_field(header->rdevmajor, sizeof(header->rdevmajor)) == 0 - || validate_number_field(header->rdevminor, sizeof(header->rdevminor)) == 0)) { + || validate_number_field(header->rdevminor, sizeof(header->rdevminor)) == 0) { bid = 0; } @@ -2110,6 +2109,21 @@ pax_attribute(struct archive_read *a, struct tar *tar, /* "size" is the size of the data in the entry. */ tar->entry_bytes_remaining = tar_atol10(value, strlen(value)); + if (tar->entry_bytes_remaining < 0) { + tar->entry_bytes_remaining = 0; + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Tar size attribute is negative"); + return (ARCHIVE_FATAL); + } + if (tar->entry_bytes_remaining == INT64_MAX) { + /* Note: tar_atol returns INT64_MAX on overflow */ + tar->entry_bytes_remaining = 0; + archive_set_error(&a->archive, + ARCHIVE_ERRNO_MISC, + "Tar size attribute overflow"); + return (ARCHIVE_FATAL); + } /* * The "size" pax header keyword always overrides the * "size" field in the tar header. diff --git a/contrib/libarchive/libarchive/archive_read_support_format_xar.c b/contrib/libarchive/libarchive/archive_read_support_format_xar.c index 503ff58b91db..ec5b06edacd5 100644 --- a/contrib/libarchive/libarchive/archive_read_support_format_xar.c +++ b/contrib/libarchive/libarchive/archive_read_support_format_xar.c @@ -624,7 +624,9 @@ read_toc(struct archive_read *a) __archive_read_consume(a, xar->toc_chksum_size); xar->offset += xar->toc_chksum_size; if (r != ARCHIVE_OK) +#ifndef DONT_FAIL_ON_CRC_ERROR return (ARCHIVE_FATAL); +#endif } /* @@ -827,10 +829,12 @@ xar_read_header(struct archive_read *a, struct archive_entry *entry) xattr->a_sum.val, xattr->a_sum.len, xattr->e_sum.val, xattr->e_sum.len); if (r != ARCHIVE_OK) { +#ifndef DONT_FAIL_ON_CRC_ERROR archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, "Xattr checksum error"); r = ARCHIVE_WARN; break; +#endif } if (xattr->name.s == NULL) { archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC, diff --git a/contrib/libarchive/libarchive/archive_string.c b/contrib/libarchive/libarchive/archive_string.c index ac66eee2c496..0fd918f47909 100644 --- a/contrib/libarchive/libarchive/archive_string.c +++ b/contrib/libarchive/libarchive/archive_string.c @@ -3988,10 +3988,10 @@ int archive_mstring_get_mbs_l(struct archive *a, struct archive_mstring *aes, const char **p, size_t *length, struct archive_string_conv *sc) { - int r, ret = 0; - - (void)r; /* UNUSED */ + int ret = 0; #if defined(_WIN32) && !defined(__CYGWIN__) + int r; + /* * Internationalization programming on Windows must use Wide * characters because Windows platform cannot make locale UTF-8. diff --git a/contrib/libarchive/libarchive/archive_write.c b/contrib/libarchive/libarchive/archive_write.c index 7d308a2ba8a5..3d3ba41f523e 100644 --- a/contrib/libarchive/libarchive/archive_write.c +++ b/contrib/libarchive/libarchive/archive_write.c @@ -201,6 +201,10 @@ __archive_write_allocate_filter(struct archive *_a) struct archive_write_filter *f; f = calloc(1, sizeof(*f)); + + if (f == NULL) + return (NULL); + f->archive = _a; f->state = ARCHIVE_WRITE_FILTER_STATE_NEW; if (a->filter_first == NULL) @@ -548,6 +552,10 @@ archive_write_open2(struct archive *_a, void *client_data, a->client_data = client_data; client_filter = __archive_write_allocate_filter(_a); + + if (client_filter == NULL) + return (ARCHIVE_FATAL); + client_filter->open = archive_write_client_open; client_filter->write = archive_write_client_write; client_filter->close = archive_write_client_close; diff --git a/contrib/libarchive/libarchive/archive_write_disk_posix.c b/contrib/libarchive/libarchive/archive_write_disk_posix.c index a82dc83f4cda..1a36e6708c49 100644 --- a/contrib/libarchive/libarchive/archive_write_disk_posix.c +++ b/contrib/libarchive/libarchive/archive_write_disk_posix.c @@ -1996,6 +1996,8 @@ archive_write_disk_new(void) free(a); return (NULL); } + a->path_safe.s[0] = 0; + #ifdef HAVE_ZLIB_H a->decmpfs_compression_level = 5; #endif @@ -2793,7 +2795,7 @@ check_symlinks_fsobj(char *path, int *a_eno, struct archive_string *a_estr, char *tail; char *head; int last; - char c; + char c = '\0'; int r; struct stat st; int chdir_fd; diff --git a/contrib/libarchive/libarchive/archive_write_open.3 b/contrib/libarchive/libarchive/archive_write_open.3 index 29bffe49eb97..6bceb964f582 100644 --- a/contrib/libarchive/libarchive/archive_write_open.3 +++ b/contrib/libarchive/libarchive/archive_write_open.3 @@ -218,6 +218,7 @@ On failure, the callback should invoke .Fn archive_set_error to register an error code and message and return +.Cm ARCHIVE_FATAL . .Bl -item -offset indent .It .Ft typedef int diff --git a/contrib/libarchive/libarchive/archive_write_set_format_pax.c b/contrib/libarchive/libarchive/archive_write_set_format_pax.c index ec7d8eb6de88..a2e6d9ad1c53 100644 --- a/contrib/libarchive/libarchive/archive_write_set_format_pax.c +++ b/contrib/libarchive/libarchive/archive_write_set_format_pax.c @@ -1717,7 +1717,7 @@ build_pax_attribute_name(char *dest, const char *src) * to having clients override it. */ #if HAVE_GETPID && 0 /* Disable this for now; see above comment. */ - sprintf(buff, "PaxHeader.%d", getpid()); + snprintf(buff, sizeof(buff), "PaxHeader.%d", getpid()); #else /* If the platform can't fetch the pid, don't include it. */ strcpy(buff, "PaxHeader"); diff --git a/contrib/libarchive/libarchive/filter_fork_posix.c b/contrib/libarchive/libarchive/filter_fork_posix.c index ac255c4f8b20..62085a7099b7 100644 --- a/contrib/libarchive/libarchive/filter_fork_posix.c +++ b/contrib/libarchive/libarchive/filter_fork_posix.c @@ -76,7 +76,7 @@ int __archive_create_child(const char *cmd, int *child_stdin, int *child_stdout, pid_t *out_child) { - pid_t child; + pid_t child = -1; int stdin_pipe[2], stdout_pipe[2], tmp; #if HAVE_POSIX_SPAWNP posix_spawn_file_actions_t actions; diff --git a/contrib/libarchive/libarchive/test/test_acl_platform_nfs4.c b/contrib/libarchive/libarchive/test/test_acl_platform_nfs4.c index ae4bb5a10125..6a5b4394f8bc 100644 --- a/contrib/libarchive/libarchive/test/test_acl_platform_nfs4.c +++ b/contrib/libarchive/libarchive/test/test_acl_platform_nfs4.c @@ -907,7 +907,7 @@ DEFINE_TEST(test_acl_platform_nfs4) assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); for (i = 0; i < acls_dir_cnt; ++i) { - sprintf(buff, "dir%d", i); + snprintf(buff, sizeof(buff), "dir%d", i); archive_entry_set_pathname(ae, buff); archive_entry_set_filetype(ae, AE_IFDIR); archive_entry_set_perm(ae, 0654); @@ -960,7 +960,7 @@ DEFINE_TEST(test_acl_platform_nfs4) /* Verify single-permission dirs on disk. */ for (i = 0; i < dircnt; ++i) { - sprintf(buff, "dir%d", i); + snprintf(buff, sizeof(buff), "dir%d", i); assertEqualInt(0, stat(buff, &st)); assertEqualInt(st.st_mtime, 123456 + i); #if ARCHIVE_ACL_SUNOS_NFS4 diff --git a/contrib/libarchive/libarchive/test/test_archive_api_feature.c b/contrib/libarchive/libarchive/test/test_archive_api_feature.c index e4239feba178..343710cfbb16 100644 --- a/contrib/libarchive/libarchive/test/test_archive_api_feature.c +++ b/contrib/libarchive/libarchive/test/test_archive_api_feature.c @@ -32,7 +32,7 @@ DEFINE_TEST(test_archive_api_feature) /* This is the (hopefully) final versioning API. */ assertEqualInt(ARCHIVE_VERSION_NUMBER, archive_version_number()); - sprintf(buff, "libarchive %d.%d.%d", + snprintf(buff, sizeof(buff), "libarchive %d.%d.%d", archive_version_number() / 1000000, (archive_version_number() / 1000) % 1000, archive_version_number() % 1000); diff --git a/contrib/libarchive/libarchive/test/test_archive_match_time.c b/contrib/libarchive/libarchive/test/test_archive_match_time.c index c6864b3265e4..23754a1538b1 100644 --- a/contrib/libarchive/libarchive/test/test_archive_match_time.c +++ b/contrib/libarchive/libarchive/test/test_archive_match_time.c @@ -321,6 +321,11 @@ test_newer_ctime_than_file_mbs(void) struct archive_entry *ae; struct archive *m; +#if defined(_WIN32) && !defined(__CYGWIN__) + skipping("Can't set ctime on Windows"); + return; +#endif + if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { @@ -435,6 +440,11 @@ test_newer_ctime_than_file_wcs(void) struct archive_entry *ae; struct archive *m; +#if defined(_WIN32) && !defined(__CYGWIN__) + skipping("Can't set ctime on Windows"); + return; +#endif + if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { @@ -782,6 +792,11 @@ test_older_ctime_than_file_mbs(void) struct archive_entry *ae; struct archive *m; +#if defined(_WIN32) && !defined(__CYGWIN__) + skipping("Can't set ctime on Windows"); + return; +#endif + if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { @@ -897,6 +912,11 @@ test_older_ctime_than_file_wcs(void) struct archive_entry *ae; struct archive *m; +#if defined(_WIN32) && !defined(__CYGWIN__) + skipping("Can't set ctime on Windows"); + return; +#endif + if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { @@ -1073,6 +1093,11 @@ test_ctime_between_files_mbs(void) struct archive_entry *ae; struct archive *m; +#if defined(_WIN32) && !defined(__CYGWIN__) + skipping("Can't set ctime on Windows"); + return; +#endif + if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { @@ -1132,6 +1157,11 @@ test_ctime_between_files_wcs(void) struct archive_entry *ae; struct archive *m; +#if defined(_WIN32) && !defined(__CYGWIN__) + skipping("Can't set ctime on Windows"); + return; +#endif + if (!assert((m = archive_match_new()) != NULL)) return; if (!assert((ae = archive_entry_new()) != NULL)) { diff --git a/contrib/libarchive/libarchive/test/test_archive_string_conversion.c b/contrib/libarchive/libarchive/test/test_archive_string_conversion.c index fb5359b6f349..7faf58bfa117 100644 --- a/contrib/libarchive/libarchive/test/test_archive_string_conversion.c +++ b/contrib/libarchive/libarchive/test/test_archive_string_conversion.c @@ -847,6 +847,7 @@ test_archive_string_set_get(void) assertEqualInt(0, archive_mstring_update_utf8(a, &mstr, "EEEEE---H")); check_string(a, &mstr, sc, "EEEEE---H", L"EEEEE---H"); + archive_mstring_clean(&mstr); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); } diff --git a/contrib/libarchive/libarchive/test/test_read_format_mtree.c b/contrib/libarchive/libarchive/test/test_read_format_mtree.c index 7e8b5701540c..500fd5384a5d 100644 --- a/contrib/libarchive/libarchive/test/test_read_format_mtree.c +++ b/contrib/libarchive/libarchive/test/test_read_format_mtree.c @@ -789,6 +789,7 @@ DEFINE_TEST(test_read_format_mtree_nonexistent_contents_file) assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); } + /* * Check mtree file with non-printable ascii characters */ @@ -814,3 +815,32 @@ DEFINE_TEST(test_read_format_mtree_noprint) assertEqualInt(ARCHIVE_OK, archive_read_close(a)); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); } + +/* + * Check mtree file with tab characters, which are supported but not printable + */ +DEFINE_TEST(test_read_format_mtree_tab) +{ + static char archive[] = + "#mtree\n" + "\ta\ttype=file\n"; + struct archive_entry *ae; + struct archive *a; + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_filter_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_memory(a, archive, sizeof(archive))); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "a"); + assertEqualInt(archive_entry_filetype(ae), AE_IFREG); + + assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); + assertEqualInt(1, archive_file_count(a)); + assertEqualInt(ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); +} diff --git a/contrib/libarchive/libarchive/test/test_read_format_rar5.c b/contrib/libarchive/libarchive/test/test_read_format_rar5.c index acc90510946b..54aae0ed1784 100644 --- a/contrib/libarchive/libarchive/test/test_read_format_rar5.c +++ b/contrib/libarchive/libarchive/test/test_read_format_rar5.c @@ -168,7 +168,7 @@ DEFINE_TEST(test_read_format_rar5_compressed) assertEqualInt(DATA_SIZE, archive_entry_size(ae)); assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE)); assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); - verify_data(buff, 0, DATA_SIZE); + assertA(1 == verify_data(buff, 0, DATA_SIZE)); EPILOGUE(); } @@ -187,25 +187,25 @@ DEFINE_TEST(test_read_format_rar5_multiple_files) assertEqualString("test1.bin", archive_entry_pathname(ae)); assertEqualInt(DATA_SIZE, archive_entry_size(ae)); assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE)); - assertA(verify_data(buff, 1, DATA_SIZE)); + assertA(1 == verify_data(buff, 1, DATA_SIZE)); assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("test2.bin", archive_entry_pathname(ae)); assertEqualInt(DATA_SIZE, archive_entry_size(ae)); assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE)); - assertA(verify_data(buff, 2, DATA_SIZE)); + assertA(1 == verify_data(buff, 2, DATA_SIZE)); assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("test3.bin", archive_entry_pathname(ae)); assertEqualInt(DATA_SIZE, archive_entry_size(ae)); assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE)); - assertA(verify_data(buff, 3, DATA_SIZE)); + assertA(1 == verify_data(buff, 3, DATA_SIZE)); assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("test4.bin", archive_entry_pathname(ae)); assertEqualInt(DATA_SIZE, archive_entry_size(ae)); assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE)); - assertA(verify_data(buff, 4, DATA_SIZE)); + assertA(1 == verify_data(buff, 4, DATA_SIZE)); /* There should be no more files in this archive. */ @@ -230,25 +230,25 @@ DEFINE_TEST(test_read_format_rar5_multiple_files_solid) assertEqualString("test1.bin", archive_entry_pathname(ae)); assertEqualInt(DATA_SIZE, archive_entry_size(ae)); assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE)); - assertA(verify_data(buff, 1, DATA_SIZE)); + assertA(1 == verify_data(buff, 1, DATA_SIZE)); assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("test2.bin", archive_entry_pathname(ae)); assertEqualInt(DATA_SIZE, archive_entry_size(ae)); assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE)); - assertA(verify_data(buff, 2, DATA_SIZE)); + assertA(1 == verify_data(buff, 2, DATA_SIZE)); assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("test3.bin", archive_entry_pathname(ae)); assertEqualInt(DATA_SIZE, archive_entry_size(ae)); assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE)); - assertA(verify_data(buff, 3, DATA_SIZE)); + assertA(1 == verify_data(buff, 3, DATA_SIZE)); assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("test4.bin", archive_entry_pathname(ae)); assertEqualInt(DATA_SIZE, archive_entry_size(ae)); assertA(DATA_SIZE == archive_read_data(a, buff, DATA_SIZE)); - assertA(verify_data(buff, 4, DATA_SIZE)); + assertA(1 == verify_data(buff, 4, DATA_SIZE)); assertA(ARCHIVE_EOF == archive_read_next_header(a, &ae)); EPILOGUE(); @@ -1346,4 +1346,27 @@ DEFINE_TEST(test_read_format_rar5_bad_window_size_in_multiarchive_file) while(0 < archive_read_data(a, buf, sizeof(buf))) {} EPILOGUE(); -}
\ No newline at end of file +} + +DEFINE_TEST(test_read_format_rar5_read_data_block_uninitialized_offset) +{ + const void *buf; + size_t size; + la_int64_t offset; + + PROLOGUE("test_read_format_rar5_compressed.rar"); + assertA(0 == archive_read_next_header(a, &ae)); + + /* A real code may pass a pointer to an uninitialized variable as an offset + * output argument. Here we want to check this situation. But because + * relying on a value of an uninitialized variable in a test is not a good + * idea, let's pretend that 0xdeadbeef is a random value of the + * uninitialized variable. */ + offset = 0xdeadbeef; + assertEqualInt(ARCHIVE_OK, archive_read_data_block(a, &buf, &size, &offset)); + /* The test archive doesn't contain a sparse file. And because of that, here + * we assume that the first returned offset should be 0. */ + assertEqualInt(0, offset); + + EPILOGUE(); +} diff --git a/contrib/libarchive/libarchive/test/test_read_format_tar_invalid_pax_size.c b/contrib/libarchive/libarchive/test/test_read_format_tar_invalid_pax_size.c new file mode 100644 index 000000000000..0a03cb677593 --- /dev/null +++ b/contrib/libarchive/libarchive/test/test_read_format_tar_invalid_pax_size.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c) 2020 Ben Wagner + * 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$"); + +/* + * The pax size attribute can be used to override the size. + * It should be validated the same way the normal size is validated. + * The test data is fuzzer output from + * https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=48467 . + */ +DEFINE_TEST(test_read_format_tar_invalid_pax_size) +{ + /* + * An archive that contains a PAX 'size' record with a large negative value. + */ + struct archive_entry *ae; + struct archive *a; + const char *refname = "test_read_format_tar_invalid_pax_size.tar"; + + extract_reference_file(refname); + assert((a = archive_read_new()) != NULL); + assertEqualInt(ARCHIVE_OK, archive_read_support_filter_all(a)); + assertEqualInt(ARCHIVE_OK, archive_read_support_format_all(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, refname, 10240)); + /* This assert will pass a normal debug build without the pax size check. */ + /* Run this test with `-fsanitize=undefined` to verify. */ + assertEqualIntA(a, ARCHIVE_FATAL, archive_read_next_header(a, &ae)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); +} diff --git a/contrib/libarchive/libarchive/test/test_read_format_tar_invalid_pax_size.tar.uu b/contrib/libarchive/libarchive/test/test_read_format_tar_invalid_pax_size.tar.uu new file mode 100644 index 000000000000..71309eab2cb3 --- /dev/null +++ b/contrib/libarchive/libarchive/test/test_read_format_tar_invalid_pax_size.tar.uu @@ -0,0 +1,38 @@ +begin 644 test_read_format_tar_invalid_pax_size.tar.uu +M+B]087A(96%D97)S+C$T-#8S+V%A80`````````````````````````````` +M```````````````````````````````````````````````````````````` +M`````````````#`P,#`V-#0`,#`P,#`P,``P,#`P,#`P`#`P,#`P,#`P,S$R +M`#$R-3,Q,30U,S<Q`"`Q,30R,"`@>``````````````````````````````` +M```````````````````````````````````````````````````````````` +M``````````````````````````````````````````!U='-A<@`P,``````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````S,"`@("`@(#T@("`@("`@("`@("`@("`@("`@ +M(`HS,"`@("`@(#T@("`@("`@("`@("`@("`@("`@(`HS,"`@("`@("`]("`@ +M("`@("`@("`@("`@("`@(`HS,"!S:7IE/2TQ.3<V.30Q,3$Q,S8U.3<R-S0S +M-@H@("`@("`@("`@_R`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ +M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ +M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ +M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ +M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ +M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ +M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@____("`@("`@("`@ +M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@ +M("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@("`@(&%A80`````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````P +M,#,P.#$V`#`S-S0U,S0`,#`Q,38Q,``P,#`P,#`P,#`P-P`Q,C4S,3$T-3,W +M,``@,3(P-S$@(#$````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M````=7-T87(`,#!D=GEU:V]V````````````````````````````````96YG +M`````````````````````````/\!````````````````,#`Q`#`P,#`P,#`P +M,#`P````````````````````````````````````````````````````]P`` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +M```````````````````````````````````````````````````````````` +&```````` +` +end diff --git a/contrib/libarchive/libarchive/test/test_read_truncated_filter.c b/contrib/libarchive/libarchive/test/test_read_truncated_filter.c index 532e3eeec6f7..f85ccaa140e3 100644 --- a/contrib/libarchive/libarchive/test/test_read_truncated_filter.c +++ b/contrib/libarchive/libarchive/test/test_read_truncated_filter.c @@ -81,7 +81,7 @@ test_truncation(const char *compression, archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < 100; i++) { - sprintf(path, "%s%d", compression, i); + snprintf(path, sizeof(path), "%s%d", compression, i); archive_entry_copy_pathname(ae, path); failure("%s", path); if (!assertEqualIntA(a, ARCHIVE_OK, @@ -123,7 +123,7 @@ test_truncation(const char *compression, assert(NULL != archive_error_string(a)); break; } - sprintf(path, "%s%d", compression, i); + snprintf(path, sizeof(path), "%s%d", compression, i); assertEqualString(path, archive_entry_pathname(ae)); if (datasize != (size_t)archive_read_data(a, data, datasize)) { failure("Should have non-NULL error message for %s", diff --git a/contrib/libarchive/libarchive/test/test_sparse_basic.c b/contrib/libarchive/libarchive/test/test_sparse_basic.c index 133a85398547..484c28656172 100644 --- a/contrib/libarchive/libarchive/test/test_sparse_basic.c +++ b/contrib/libarchive/libarchive/test/test_sparse_basic.c @@ -253,8 +253,10 @@ is_sparse_supported(const char *path) #if defined(HAVE_LINUX_FIEMAP_H) if (r < 0) return (is_sparse_supported_fiemap(path)); -#endif + return (1); +#else return (r >= 0); +#endif } #elif !defined(HAVE_LINUX_FIEMAP_H) diff --git a/contrib/libarchive/libarchive/test/test_tar_large.c b/contrib/libarchive/libarchive/test/test_tar_large.c index 6fb77768ba46..8a9405b68e64 100644 --- a/contrib/libarchive/libarchive/test/test_tar_large.c +++ b/contrib/libarchive/libarchive/test/test_tar_large.c @@ -224,7 +224,7 @@ DEFINE_TEST(test_tar_large) */ for (i = 0; tests[i] != 0; i++) { assert((ae = archive_entry_new()) != NULL); - sprintf(namebuff, "file_%d", i); + snprintf(namebuff, sizeof(namebuff), "file_%d", i); archive_entry_copy_pathname(ae, namebuff); archive_entry_set_mode(ae, S_IFREG | 0755); filesize = tests[i]; @@ -271,7 +271,7 @@ DEFINE_TEST(test_tar_large) */ for (i = 0; tests[i] > 0; i++) { assertEqualIntA(a, 0, archive_read_next_header(a, &ae)); - sprintf(namebuff, "file_%d", i); + snprintf(namebuff, sizeof(namebuff), "file_%d", i); assertEqualString(namebuff, archive_entry_pathname(ae)); assert(tests[i] == archive_entry_size(ae)); } diff --git a/contrib/libarchive/libarchive/test/test_write_disk_secure744.c b/contrib/libarchive/libarchive/test/test_write_disk_secure744.c index 08c725e12b80..9b12d4cf1082 100644 --- a/contrib/libarchive/libarchive/test/test_write_disk_secure744.c +++ b/contrib/libarchive/libarchive/test/test_write_disk_secure744.c @@ -75,7 +75,7 @@ DEFINE_TEST(test_write_disk_secure744) archive_entry_free(ae); *p++ = '/'; - sprintf(p, "target%d", n); + snprintf(p, buff_size - (p - buff), "target%d", n); /* Try to create a file through the symlink, should fail. */ assert((ae = archive_entry_new()) != NULL); diff --git a/contrib/libarchive/libarchive/test/test_write_filter_b64encode.c b/contrib/libarchive/libarchive/test/test_write_filter_b64encode.c index 665087b97885..5b917e92a30a 100644 --- a/contrib/libarchive/libarchive/test/test_write_filter_b64encode.c +++ b/contrib/libarchive/libarchive/test/test_write_filter_b64encode.c @@ -64,7 +64,7 @@ DEFINE_TEST(test_write_filter_b64encode) assert((ae = archive_entry_new()) != NULL); archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize @@ -79,7 +79,7 @@ DEFINE_TEST(test_write_filter_b64encode) assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); for (i = 0; i < 99; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualIntA(a, 0, archive_read_next_header(a, &ae))) break; assertEqualString(path, archive_entry_pathname(ae)); @@ -111,7 +111,7 @@ DEFINE_TEST(test_write_filter_b64encode) assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 99; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -128,7 +128,7 @@ DEFINE_TEST(test_write_filter_b64encode) assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 99; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(0, archive_read_next_header(a, &ae))) break; assertEqualString(path, archive_entry_pathname(ae)); diff --git a/contrib/libarchive/libarchive/test/test_write_filter_bzip2.c b/contrib/libarchive/libarchive/test/test_write_filter_bzip2.c index 4f32d28cbed4..9e089c0dfdb5 100644 --- a/contrib/libarchive/libarchive/test/test_write_filter_bzip2.c +++ b/contrib/libarchive/libarchive/test/test_write_filter_bzip2.c @@ -83,7 +83,7 @@ DEFINE_TEST(test_write_filter_bzip2) archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize @@ -99,7 +99,7 @@ DEFINE_TEST(test_write_filter_bzip2) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(0, archive_read_next_header(a, &ae))) break; assertEqualString(path, archive_entry_pathname(ae)); @@ -133,7 +133,7 @@ DEFINE_TEST(test_write_filter_bzip2) assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -160,7 +160,7 @@ DEFINE_TEST(test_write_filter_bzip2) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(0, archive_read_next_header(a, &ae))) break; assertEqualString(path, archive_entry_pathname(ae)); @@ -187,7 +187,7 @@ DEFINE_TEST(test_write_filter_bzip2) assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -212,7 +212,7 @@ DEFINE_TEST(test_write_filter_bzip2) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 999; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(0, archive_read_next_header(a, &ae))) break; assertEqualString(path, archive_entry_pathname(ae)); diff --git a/contrib/libarchive/libarchive/test/test_write_filter_compress.c b/contrib/libarchive/libarchive/test/test_write_filter_compress.c index 1b8910e51adb..5cc0fc80bd8c 100644 --- a/contrib/libarchive/libarchive/test/test_write_filter_compress.c +++ b/contrib/libarchive/libarchive/test/test_write_filter_compress.c @@ -59,7 +59,7 @@ DEFINE_TEST(test_write_filter_compress) archive_write_open_memory(a, buff, buffsize, &used)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -83,7 +83,7 @@ DEFINE_TEST(test_write_filter_compress) for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(0, archive_read_next_header(a, &ae))) break; assertEqualString(path, archive_entry_pathname(ae)); diff --git a/contrib/libarchive/libarchive/test/test_write_filter_gzip.c b/contrib/libarchive/libarchive/test/test_write_filter_gzip.c index 935fb51f5140..2b761627179e 100644 --- a/contrib/libarchive/libarchive/test/test_write_filter_gzip.c +++ b/contrib/libarchive/libarchive/test/test_write_filter_gzip.c @@ -85,7 +85,7 @@ DEFINE_TEST(test_write_filter_gzip) archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize @@ -113,7 +113,7 @@ DEFINE_TEST(test_write_filter_gzip) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; @@ -148,7 +148,7 @@ DEFINE_TEST(test_write_filter_gzip) archive_write_set_options(a, "gzip:compression-level=9")); assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -187,7 +187,7 @@ DEFINE_TEST(test_write_filter_gzip) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; @@ -212,7 +212,7 @@ DEFINE_TEST(test_write_filter_gzip) assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -249,7 +249,7 @@ DEFINE_TEST(test_write_filter_gzip) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; diff --git a/contrib/libarchive/libarchive/test/test_write_filter_lrzip.c b/contrib/libarchive/libarchive/test/test_write_filter_lrzip.c index f28c8358363d..2efc2ec284a4 100644 --- a/contrib/libarchive/libarchive/test/test_write_filter_lrzip.c +++ b/contrib/libarchive/libarchive/test/test_write_filter_lrzip.c @@ -68,7 +68,7 @@ DEFINE_TEST(test_write_filter_lrzip) archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize @@ -84,7 +84,7 @@ DEFINE_TEST(test_write_filter_lrzip) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; diff --git a/contrib/libarchive/libarchive/test/test_write_filter_lz4.c b/contrib/libarchive/libarchive/test/test_write_filter_lz4.c index 4f2135a31507..071fee41dd95 100644 --- a/contrib/libarchive/libarchive/test/test_write_filter_lz4.c +++ b/contrib/libarchive/libarchive/test/test_write_filter_lz4.c @@ -84,7 +84,7 @@ DEFINE_TEST(test_write_filter_lz4) archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize @@ -107,7 +107,7 @@ DEFINE_TEST(test_write_filter_lz4) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; @@ -142,7 +142,7 @@ DEFINE_TEST(test_write_filter_lz4) assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -170,7 +170,7 @@ DEFINE_TEST(test_write_filter_lz4) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; @@ -195,7 +195,7 @@ DEFINE_TEST(test_write_filter_lz4) assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -225,7 +225,7 @@ DEFINE_TEST(test_write_filter_lz4) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; @@ -330,7 +330,7 @@ test_options(const char *options) archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize @@ -350,7 +350,7 @@ test_options(const char *options) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; diff --git a/contrib/libarchive/libarchive/test/test_write_filter_lzip.c b/contrib/libarchive/libarchive/test/test_write_filter_lzip.c index 145a3084d3de..ce70a5d629a7 100644 --- a/contrib/libarchive/libarchive/test/test_write_filter_lzip.c +++ b/contrib/libarchive/libarchive/test/test_write_filter_lzip.c @@ -81,7 +81,7 @@ DEFINE_TEST(test_write_filter_lzip) archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize @@ -103,7 +103,7 @@ DEFINE_TEST(test_write_filter_lzip) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; @@ -133,7 +133,7 @@ DEFINE_TEST(test_write_filter_lzip) archive_write_set_filter_option(a, NULL, "compression-level", "9")); assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -157,7 +157,7 @@ DEFINE_TEST(test_write_filter_lzip) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); failure("Trying to read %s", path); if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))) @@ -181,7 +181,7 @@ DEFINE_TEST(test_write_filter_lzip) archive_write_set_filter_option(a, NULL, "compression-level", "0")); assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -210,7 +210,7 @@ DEFINE_TEST(test_write_filter_lzip) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; diff --git a/contrib/libarchive/libarchive/test/test_write_filter_lzma.c b/contrib/libarchive/libarchive/test/test_write_filter_lzma.c index 68e489832504..d055333a44c3 100644 --- a/contrib/libarchive/libarchive/test/test_write_filter_lzma.c +++ b/contrib/libarchive/libarchive/test/test_write_filter_lzma.c @@ -80,7 +80,7 @@ DEFINE_TEST(test_write_filter_lzma) archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize @@ -102,7 +102,7 @@ DEFINE_TEST(test_write_filter_lzma) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; @@ -132,7 +132,7 @@ DEFINE_TEST(test_write_filter_lzma) archive_write_set_filter_option(a, NULL, "compression-level", "9")); assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -156,7 +156,7 @@ DEFINE_TEST(test_write_filter_lzma) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); failure("Trying to read %s", path); if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))) @@ -180,7 +180,7 @@ DEFINE_TEST(test_write_filter_lzma) archive_write_set_filter_option(a, NULL, "compression-level", "0")); assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -214,7 +214,7 @@ DEFINE_TEST(test_write_filter_lzma) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; diff --git a/contrib/libarchive/libarchive/test/test_write_filter_lzop.c b/contrib/libarchive/libarchive/test/test_write_filter_lzop.c index 92db7bf3dc43..18fc332b44ff 100644 --- a/contrib/libarchive/libarchive/test/test_write_filter_lzop.c +++ b/contrib/libarchive/libarchive/test/test_write_filter_lzop.c @@ -79,7 +79,7 @@ DEFINE_TEST(test_write_filter_lzop) archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize @@ -99,7 +99,7 @@ DEFINE_TEST(test_write_filter_lzop) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; @@ -135,7 +135,7 @@ DEFINE_TEST(test_write_filter_lzop) assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -163,7 +163,7 @@ DEFINE_TEST(test_write_filter_lzop) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; @@ -188,7 +188,7 @@ DEFINE_TEST(test_write_filter_lzop) assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -218,7 +218,7 @@ DEFINE_TEST(test_write_filter_lzop) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < filecount; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; diff --git a/contrib/libarchive/libarchive/test/test_write_filter_uuencode.c b/contrib/libarchive/libarchive/test/test_write_filter_uuencode.c index 57a4b49bd2a6..2ce5b8931447 100644 --- a/contrib/libarchive/libarchive/test/test_write_filter_uuencode.c +++ b/contrib/libarchive/libarchive/test/test_write_filter_uuencode.c @@ -64,7 +64,7 @@ DEFINE_TEST(test_write_filter_uuencode) assert((ae = archive_entry_new()) != NULL); archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize @@ -79,7 +79,7 @@ DEFINE_TEST(test_write_filter_uuencode) assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); for (i = 0; i < 99; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualIntA(a, 0, archive_read_next_header(a, &ae))) break; assertEqualString(path, archive_entry_pathname(ae)); @@ -111,7 +111,7 @@ DEFINE_TEST(test_write_filter_uuencode) assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 99; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -128,7 +128,7 @@ DEFINE_TEST(test_write_filter_uuencode) assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 99; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(0, archive_read_next_header(a, &ae))) break; assertEqualString(path, archive_entry_pathname(ae)); diff --git a/contrib/libarchive/libarchive/test/test_write_filter_xz.c b/contrib/libarchive/libarchive/test/test_write_filter_xz.c index bf1265c65b6f..e2f1ec821425 100644 --- a/contrib/libarchive/libarchive/test/test_write_filter_xz.c +++ b/contrib/libarchive/libarchive/test/test_write_filter_xz.c @@ -80,7 +80,7 @@ DEFINE_TEST(test_write_filter_xz) archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize @@ -102,7 +102,7 @@ DEFINE_TEST(test_write_filter_xz) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; @@ -132,7 +132,7 @@ DEFINE_TEST(test_write_filter_xz) archive_write_set_filter_option(a, NULL, "compression-level", "9")); assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -163,7 +163,7 @@ DEFINE_TEST(test_write_filter_xz) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); failure("Trying to read %s", path); if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))) @@ -187,7 +187,7 @@ DEFINE_TEST(test_write_filter_xz) archive_write_set_filter_option(a, NULL, "compression-level", "0")); assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -220,7 +220,7 @@ DEFINE_TEST(test_write_filter_xz) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; diff --git a/contrib/libarchive/libarchive/test/test_write_filter_zstd.c b/contrib/libarchive/libarchive/test/test_write_filter_zstd.c index 6601e6aaf898..263cea5bc49e 100644 --- a/contrib/libarchive/libarchive/test/test_write_filter_zstd.c +++ b/contrib/libarchive/libarchive/test/test_write_filter_zstd.c @@ -74,7 +74,7 @@ DEFINE_TEST(test_write_filter_zstd) archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize @@ -96,7 +96,7 @@ DEFINE_TEST(test_write_filter_zstd) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used1)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); if (!assertEqualInt(ARCHIVE_OK, archive_read_next_header(a, &ae))) break; @@ -135,7 +135,7 @@ DEFINE_TEST(test_write_filter_zstd) archive_write_set_filter_option(a, NULL, "threads", "4")); assertEqualIntA(a, ARCHIVE_OK, archive_write_open_memory(a, buff, buffsize, &used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, path); archive_entry_set_size(ae, datasize); @@ -158,7 +158,7 @@ DEFINE_TEST(test_write_filter_zstd) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used2)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); failure("Trying to read %s", path); if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))) @@ -185,7 +185,7 @@ DEFINE_TEST(test_write_filter_zstd) archive_entry_set_filetype(ae, AE_IFREG); archive_entry_set_size(ae, datasize); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); archive_entry_copy_pathname(ae, path); assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae)); assertA(datasize == (size_t)archive_write_data(a, data, datasize)); @@ -205,7 +205,7 @@ DEFINE_TEST(test_write_filter_zstd) assertEqualIntA(a, ARCHIVE_OK, archive_read_open_memory(a, buff, used3)); for (i = 0; i < 100; i++) { - sprintf(path, "file%03d", i); + snprintf(path, sizeof(path), "file%03d", i); failure("Trying to read %s", path); if (!assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae))) diff --git a/contrib/libarchive/libarchive/test/test_write_format_zip_compression_store.c b/contrib/libarchive/libarchive/test/test_write_format_zip_compression_store.c index c969a41d4d41..ed0908787579 100644 --- a/contrib/libarchive/libarchive/test/test_write_format_zip_compression_store.c +++ b/contrib/libarchive/libarchive/test/test_write_format_zip_compression_store.c @@ -128,12 +128,31 @@ static void verify_uncompressed_contents(const char *buff, size_t used) /* Misc variables */ unsigned long crc; - struct tm *tm = localtime(&now); - + struct tm *tm; +#if defined(HAVE_LOCALTIME_R) || defined(HAVE__LOCALTIME64_S) + struct tm tmbuf; +#endif +#if defined(HAVE__LOCALTIME64_S) + errno_t terr; + __time64_t tmptime; +#endif /* p is the pointer to walk over the central directory, * q walks over the local headers, the data and the data descriptors. */ const char *p, *q, *local_header, *extra_start; +#if defined(HAVE_LOCALTIME_R) + tm = localtime_r(&now, &tmbuf); +#elif defined(HAVE__LOCALTIME64_S) + tmptime = now; + terr = _localtime64_s(&tmbuf, &tmptime); + if (terr) + tm = NULL; + else + tm = &tmbuf; +#else + tm = localtime(&now); +#endif + /* Remember the end of the archive in memory. */ buffend = buff + used; diff --git a/contrib/libarchive/libarchive/test/test_write_format_zip_file.c b/contrib/libarchive/libarchive/test/test_write_format_zip_file.c index 2868123b08b9..7796a48cdac3 100644 --- a/contrib/libarchive/libarchive/test/test_write_format_zip_file.c +++ b/contrib/libarchive/libarchive/test/test_write_format_zip_file.c @@ -73,7 +73,14 @@ DEFINE_TEST(test_write_format_zip_file) struct archive *a; struct archive_entry *ae; time_t t = 1234567890; - struct tm *tm = localtime(&t); + struct tm *tm; +#if defined(HAVE_LOCALTIME_R) || defined(HAVE__LOCALTIME64_S) + struct tm tmbuf; +#endif +#if defined(HAVE__LOCALTIME64_S) + errno_t terr; + __time64_t tmptime; +#endif size_t used, buffsize = 1000000; unsigned long crc; int file_perm = 00644; @@ -91,6 +98,18 @@ DEFINE_TEST(test_write_format_zip_file) zip_compression = 0; #endif +#if defined(HAVE_LOCALTIME_R) + tm = localtime_r(&t, &tmbuf); +#elif defined(HAVE__LOCALTIME64_S) + tmptime = t; + terr = _localtime64_s(&tmbuf, &tmptime); + if (terr) + tm = NULL; + else + tm = &tmbuf; +#else + tm = localtime(&t); +#endif buff = malloc(buffsize); /* Create a new archive in memory. */ diff --git a/contrib/libarchive/libarchive/test/test_write_format_zip_file_zip64.c b/contrib/libarchive/libarchive/test/test_write_format_zip_file_zip64.c index 71da98668d8d..c4161bc3a89b 100644 --- a/contrib/libarchive/libarchive/test/test_write_format_zip_file_zip64.c +++ b/contrib/libarchive/libarchive/test/test_write_format_zip_file_zip64.c @@ -75,7 +75,14 @@ DEFINE_TEST(test_write_format_zip_file_zip64) struct archive *a; struct archive_entry *ae; time_t t = 1234567890; - struct tm *tm = localtime(&t); + struct tm *tm; +#if defined(HAVE_LOCALTIME_R) || defined(HAVE__LOCALTIME64_S) + struct tm tmbuf; +#endif +#if defined(HAVE__LOCALTIME64_S) + errno_t terr; + __time64_t tmptime; +#endif size_t used, buffsize = 1000000; unsigned long crc; int file_perm = 00644; @@ -92,6 +99,18 @@ DEFINE_TEST(test_write_format_zip_file_zip64) zip_compression = 0; #endif +#if defined(HAVE_LOCALTIME_R) + tm = localtime_r(&t, &tmbuf); +#elif defined(HAVE__LOCALTIME64_S) + tmptime = t; + terr = _localtime64_s(&tmbuf, &tmptime); + if (terr) + tm = NULL; + else + tm = &tmbuf; +#else + tm = localtime(&t); +#endif buff = malloc(buffsize); /* Create a new archive in memory. */ diff --git a/contrib/libarchive/libarchive/test/test_write_format_zip_large.c b/contrib/libarchive/libarchive/test/test_write_format_zip_large.c index 2f98c6d4db8a..e3594c97d398 100644 --- a/contrib/libarchive/libarchive/test/test_write_format_zip_large.c +++ b/contrib/libarchive/libarchive/test/test_write_format_zip_large.c @@ -309,7 +309,7 @@ verify_large_zip(struct archive *a, struct fileblocks *fileblocks) for (i = 0; test_sizes[i] > 0; i++) { assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); - sprintf(namebuff, "file_%d", i); + snprintf(namebuff, sizeof(namebuff), "file_%d", i); assertEqualString(namebuff, archive_entry_pathname(ae)); assertEqualInt(test_sizes[i], archive_entry_size(ae)); } @@ -359,7 +359,7 @@ DEFINE_TEST(test_write_format_zip_large) */ for (i = 0; test_sizes[i] != 0; i++) { assert((ae = archive_entry_new()) != NULL); - sprintf(namebuff, "file_%d", i); + snprintf(namebuff, sizeof(namebuff), "file_%d", i); archive_entry_copy_pathname(ae, namebuff); archive_entry_set_mode(ae, S_IFREG | 0755); filesize = test_sizes[i]; diff --git a/contrib/libarchive/tar/bsdtar.1 b/contrib/libarchive/tar/bsdtar.1 index 63774216bd86..b57835adbef2 100644 --- a/contrib/libarchive/tar/bsdtar.1 +++ b/contrib/libarchive/tar/bsdtar.1 @@ -953,7 +953,7 @@ archives. .Sh ENVIRONMENT The following environment variables affect the execution of .Nm : -.Bl -tag -width ".Ev BLOCKSIZE" +.Bl -tag -width indent .It Ev TAR_READER_OPTIONS The default options for format readers and compression readers. The diff --git a/contrib/libarchive/tar/subst.c b/contrib/libarchive/tar/subst.c index 48370b2fceeb..7f3d1819984f 100644 --- a/contrib/libarchive/tar/subst.c +++ b/contrib/libarchive/tar/subst.c @@ -320,6 +320,7 @@ cleanup_substitution(struct bsdtar *bsdtar) while ((rule = subst->first_rule) != NULL) { subst->first_rule = rule->next; free(rule->result); + regfree(&rule->re); free(rule); } free(subst); diff --git a/contrib/libarchive/tar/test/test_copy.c b/contrib/libarchive/tar/test/test_copy.c index 5d0c68718736..3092ed9d12a7 100644 --- a/contrib/libarchive/tar/test/test_copy.c +++ b/contrib/libarchive/tar/test/test_copy.c @@ -160,21 +160,21 @@ create_tree(void) failure("Internal sanity check failed: i = %d", i); assert(filenames[i] != NULL); - sprintf(buff, "f/%s", filenames[i]); + snprintf(buff, sizeof(buff), "f/%s", filenames[i]); assertMakeFile(buff, 0777, buff); /* Create a link named "l/abcdef..." to the above. */ - sprintf(buff2, "l/%s", filenames[i]); + snprintf(buff2, sizeof(buff2), "l/%s", filenames[i]); assertMakeHardlink(buff2, buff); /* Create a link named "m/abcdef..." to the above. */ - sprintf(buff2, "m/%s", filenames[i]); + snprintf(buff2, sizeof(buff2), "m/%s", filenames[i]); assertMakeHardlink(buff2, buff); if (canSymlink()) { /* Create a symlink named "s/abcdef..." to the above. */ - sprintf(buff, "s/%s", filenames[i]); - sprintf(buff2, "../f/%s", filenames[i]); + snprintf(buff, sizeof(buff), "s/%s", filenames[i]); + snprintf(buff2, sizeof(buff2), "../f/%s", filenames[i]); failure("buff=\"%s\" buff2=\"%s\"", buff, buff2); assertMakeSymlink(buff, buff2, 0); } @@ -202,13 +202,13 @@ verify_tree(size_t limit) /* Generate the names we know should be there and verify them. */ for (i = 1; i < LOOP_MAX; i++) { /* Verify a file named "f/abcdef..." */ - sprintf(name1, "f/%s", filenames[i]); + snprintf(name1, sizeof(name1), "f/%s", filenames[i]); if (i <= limit) { assertFileExists(name1); assertFileContents(name1, (int)strlen(name1), name1); } - sprintf(name2, "l/%s", filenames[i]); + snprintf(name2, sizeof(name2), "l/%s", filenames[i]); if (i + 2 <= limit) { /* Verify hardlink "l/abcdef..." */ assertIsHardlink(name1, name2); @@ -219,14 +219,14 @@ verify_tree(size_t limit) if (canSymlink()) { /* Verify symlink "s/abcdef..." */ - sprintf(name1, "s/%s", filenames[i]); - sprintf(name2, "../f/%s", filenames[i]); + snprintf(name1, sizeof(name1), "s/%s", filenames[i]); + snprintf(name2, sizeof(name2), "../f/%s", filenames[i]); if (strlen(name2) <= limit) assertIsSymlink(name1, name2, 0); } /* Verify dir "d/abcdef...". */ - sprintf(name1, "d/%s", filenames[i]); + snprintf(name1, sizeof(name1), "d/%s", filenames[i]); if (i + 1 <= limit) { /* +1 for trailing slash */ if (assertIsDir(name1, -1)) { /* TODO: opendir/readdir this diff --git a/contrib/libarchive/tar/test/test_option_b.c b/contrib/libarchive/tar/test/test_option_b.c index 0eee80d86f49..d1b75e350613 100644 --- a/contrib/libarchive/tar/test/test_option_b.c +++ b/contrib/libarchive/tar/test/test_option_b.c @@ -30,15 +30,17 @@ __FBSDID("$FreeBSD$"); DEFINE_TEST(test_option_b) { char *testprog_ustar; + size_t testprog_ustar_len; assertMakeFile("file1", 0644, "file1"); if (systemf("cat file1 > test_cat.out 2> test_cat.err") != 0) { skipping("This test requires a `cat` program"); return; } - testprog_ustar = malloc(strlen(testprog) + sizeof(USTAR_OPT) + 1); - strcpy(testprog_ustar, testprog); - strcat(testprog_ustar, USTAR_OPT); + testprog_ustar_len = strlen(testprog) + sizeof(USTAR_OPT) + 1; + testprog_ustar = malloc(testprog_ustar_len); + strncpy(testprog_ustar, testprog, testprog_ustar_len); + strncat(testprog_ustar, USTAR_OPT, testprog_ustar_len); /* * Bsdtar does not pad if the output is going directly to a disk file. diff --git a/contrib/libarchive/tar/util.c b/contrib/libarchive/tar/util.c index 9d59e1a65b26..231c53e2cf6b 100644 --- a/contrib/libarchive/tar/util.c +++ b/contrib/libarchive/tar/util.c @@ -63,7 +63,7 @@ __FBSDID("$FreeBSD$"); #include "err.h" #include "passphrase.h" -static size_t bsdtar_expand_char(char *, size_t, char); +static size_t bsdtar_expand_char(char *, size_t, size_t, char); static const char *strip_components(const char *path, int elements); #if defined(_WIN32) && !defined(__CYGWIN__) @@ -173,12 +173,12 @@ safe_fprintf(FILE *f, const char *fmt, ...) /* Not printable, format the bytes. */ while (n-- > 0) i += (unsigned)bsdtar_expand_char( - outbuff, i, *p++); + outbuff, sizeof(outbuff), i, *p++); } } else { /* After any conversion failure, don't bother * trying to convert the rest. */ - i += (unsigned)bsdtar_expand_char(outbuff, i, *p++); + i += (unsigned)bsdtar_expand_char(outbuff, sizeof(outbuff), i, *p++); try_wc = 0; } @@ -200,7 +200,7 @@ safe_fprintf(FILE *f, const char *fmt, ...) * Render an arbitrary sequence of bytes into printable ASCII characters. */ static size_t -bsdtar_expand_char(char *buff, size_t offset, char c) +bsdtar_expand_char(char *buff, size_t buffsize, size_t offset, char c) { size_t i = offset; @@ -221,7 +221,7 @@ bsdtar_expand_char(char *buff, size_t offset, char c) case '\v': buff[i++] = 'v'; break; case '\\': buff[i++] = '\\'; break; default: - sprintf(buff + i, "%03o", 0xFF & (int)c); + snprintf(buff + i, buffsize - i, "%03o", 0xFF & (int)c); i += 3; } } @@ -309,11 +309,12 @@ set_chdir(struct bsdtar *bsdtar, const char *newdir) /* The -C /foo -C bar case; concatenate */ char *old_pending = bsdtar->pending_chdir; size_t old_len = strlen(old_pending); - bsdtar->pending_chdir = malloc(old_len + strlen(newdir) + 2); + size_t new_len = old_len + strlen(newdir) + 2; + bsdtar->pending_chdir = malloc(new_len); if (old_pending[old_len - 1] == '/') old_pending[old_len - 1] = '\0'; if (bsdtar->pending_chdir != NULL) - sprintf(bsdtar->pending_chdir, "%s/%s", + snprintf(bsdtar->pending_chdir, new_len, "%s/%s", old_pending, newdir); free(old_pending); } @@ -695,7 +696,7 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry) /* Use uname if it's present, else uid. */ p = archive_entry_uname(entry); if ((p == NULL) || (*p == '\0')) { - sprintf(tmp, "%lu ", + snprintf(tmp, sizeof(tmp), "%lu ", (unsigned long)archive_entry_uid(entry)); p = tmp; } @@ -710,7 +711,7 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry) fprintf(out, "%s", p); w = strlen(p); } else { - sprintf(tmp, "%lu", + snprintf(tmp, sizeof(tmp), "%lu", (unsigned long)archive_entry_gid(entry)); w = strlen(tmp); fprintf(out, "%s", tmp); @@ -723,7 +724,7 @@ list_item_verbose(struct bsdtar *bsdtar, FILE *out, struct archive_entry *entry) */ if (archive_entry_filetype(entry) == AE_IFCHR || archive_entry_filetype(entry) == AE_IFBLK) { - sprintf(tmp, "%lu,%lu", + snprintf(tmp, sizeof(tmp), "%lu,%lu", (unsigned long)archive_entry_rdevmajor(entry), (unsigned long)archive_entry_rdevminor(entry)); } else { diff --git a/contrib/libarchive/test_utils/test_main.c b/contrib/libarchive/test_utils/test_main.c index 116da2315439..74250ad748c2 100644 --- a/contrib/libarchive/test_utils/test_main.c +++ b/contrib/libarchive/test_utils/test_main.c @@ -426,7 +426,7 @@ failure(const char *fmt, ...) nextmsg = NULL; } else { va_start(ap, fmt); - vsprintf(msgbuff, fmt, ap); + vsnprintf(msgbuff, sizeof(msgbuff), fmt, ap); va_end(ap); nextmsg = msgbuff; } @@ -551,7 +551,7 @@ test_skipping(const char *fmt, ...) va_list ap; va_start(ap, fmt); - vsprintf(buff, fmt, ap); + vsnprintf(buff, sizeof(buff), fmt, ap); va_end(ap); /* Use failure() message if set. */ msg = nextmsg; @@ -1970,7 +1970,12 @@ assertion_make_file(const char *file, int line, failure_finish(NULL); return (0); } - if (0 != chmod(path, mode)) { +#ifdef HAVE_FCHMOD + if (0 != fchmod(fd, mode)) +#else + if (0 != chmod(path, mode)) +#endif + { failure_start(file, line, "Could not chmod %s", path); failure_finish(NULL); close(fd); @@ -3065,7 +3070,7 @@ systemf(const char *fmt, ...) int r; va_start(ap, fmt); - vsprintf(buff, fmt, ap); + vsnprintf(buff, sizeof(buff), fmt, ap); if (verbosity > VERBOSITY_FULL) logprintf("Cmd: %s\n", buff); r = system(buff); @@ -3090,7 +3095,7 @@ slurpfile(size_t * sizep, const char *fmt, ...) int r; va_start(ap, fmt); - vsprintf(filename, fmt, ap); + vsnprintf(filename, sizeof(filename), fmt, ap); va_end(ap); f = fopen(filename, "rb"); @@ -3157,7 +3162,7 @@ extract_reference_file(const char *name) char buff[1024]; FILE *in, *out; - sprintf(buff, "%s/%s.uu", refdir, name); + snprintf(buff, sizeof(buff), "%s/%s.uu", refdir, name); in = fopen(buff, "r"); failure("Couldn't open reference file %s", buff); assert(in != NULL); @@ -3185,14 +3190,12 @@ extract_reference_file(const char *name) while (bytes > 0) { int n = 0; /* Write out 1-3 bytes from that. */ - if (bytes > 0) { - assert(VALID_UUDECODE(p[0])); - assert(VALID_UUDECODE(p[1])); - n = UUDECODE(*p++) << 18; - n |= UUDECODE(*p++) << 12; - fputc(n >> 16, out); - --bytes; - } + assert(VALID_UUDECODE(p[0])); + assert(VALID_UUDECODE(p[1])); + n = UUDECODE(*p++) << 18; + n |= UUDECODE(*p++) << 12; + fputc(n >> 16, out); + --bytes; if (bytes > 0) { assert(VALID_UUDECODE(p[0])); n |= UUDECODE(*p++) << 6; @@ -3218,7 +3221,7 @@ copy_reference_file(const char *name) FILE *in, *out; size_t rbytes; - sprintf(buff, "%s/%s", refdir, name); + snprintf(buff, sizeof(buff), "%s/%s", refdir, name); in = fopen(buff, "rb"); failure("Couldn't open reference file %s", buff); assert(in != NULL); @@ -3545,7 +3548,7 @@ test_run(int i, const char *tmpdir) exit(1); } /* Create a log file for this test. */ - sprintf(logfilename, "%s.log", tests[i].name); + snprintf(logfilename, sizeof(logfilename), "%s.log", tests[i].name); logfile = fopen(logfilename, "w"); fprintf(logfile, "%s\n\n", tests[i].name); /* Chdir() to a work dir for this specific test. */ @@ -3859,7 +3862,19 @@ main(int argc, char **argv) static const int limit = sizeof(tests) / sizeof(tests[0]); int test_set[sizeof(tests) / sizeof(tests[0])]; int i = 0, j = 0, tests_run = 0, tests_failed = 0, option; + int testprogdir_len; +#ifdef PROGRAM + int tmp2_len; +#endif time_t now; + struct tm *tmptr; +#if defined(HAVE_LOCALTIME_R) || defined(HAVE__LOCALTIME64_S) + struct tm tmbuf; +#endif +#if defined(HAVE__LOCALTIME64_S) + errno_t terr; + __time64_t tmptime; +#endif char *refdir_alloc = NULL; const char *progname; char **saved_argv; @@ -3895,12 +3910,13 @@ main(int argc, char **argv) * tree. */ progname = p = argv[0]; - if ((testprogdir = (char *)malloc(strlen(progname) + 1)) == NULL) + testprogdir_len = strlen(progname) + 1; + if ((testprogdir = (char *)malloc(testprogdir_len)) == NULL) { fprintf(stderr, "ERROR: Out of memory."); exit(1); } - strcpy(testprogdir, progname); + strncpy(testprogdir, progname, testprogdir_len); while (*p != '\0') { /* Support \ or / dir separators for Windows compat. */ if (*p == '/' || *p == '\\') @@ -4042,20 +4058,21 @@ main(int argc, char **argv) #ifdef PROGRAM if (testprogfile == NULL) { - if ((tmp2 = (char *)malloc(strlen(testprogdir) + 1 + - strlen(PROGRAM) + 1)) == NULL) + tmp2_len = strlen(testprogdir) + 1 + strlen(PROGRAM) + 1; + if ((tmp2 = (char *)malloc(tmp2_len)) == NULL) { fprintf(stderr, "ERROR: Out of memory."); exit(1); } - strcpy(tmp2, testprogdir); - strcat(tmp2, "/"); - strcat(tmp2, PROGRAM); + strncpy(tmp2, testprogdir, tmp2_len); + strncat(tmp2, "/", tmp2_len); + strncat(tmp2, PROGRAM, tmp2_len); testprogfile = tmp2; } { char *testprg; + int testprg_len; #if defined(_WIN32) && !defined(__CYGWIN__) /* Command.com sometimes rejects '/' separators. */ testprg = strdup(testprogfile); @@ -4066,10 +4083,11 @@ main(int argc, char **argv) testprogfile = testprg; #endif /* Quote the name that gets put into shell command lines. */ - testprg = malloc(strlen(testprogfile) + 3); - strcpy(testprg, "\""); - strcat(testprg, testprogfile); - strcat(testprg, "\""); + testprg_len = strlen(testprogfile) + 3; + testprg = malloc(testprg_len); + strncpy(testprg, "\"", testprg_len); + strncat(testprg, testprogfile, testprg_len); + strncat(testprg, "\"", testprg_len); testprog = testprg; } #endif @@ -4091,9 +4109,20 @@ main(int argc, char **argv) */ now = time(NULL); for (i = 0; ; i++) { +#if defined(HAVE_LOCALTIME_R) + tmptr = localtime_r(&now, &tmbuf); +#elif defined(HAVE__LOCALTIME64_S) + tmptime = now; + terr = _localtime64_s(&tmbuf, &tmptime); + if (terr) + tmptr = NULL; + else + tmptr = &tmbuf; +#else + tmptr = localtime(&now); +#endif strftime(tmpdir_timestamp, sizeof(tmpdir_timestamp), - "%Y-%m-%dT%H.%M.%S", - localtime(&now)); + "%Y-%m-%dT%H.%M.%S", tmptr); if ((strlen(tmp) + 1 + strlen(progname) + 1 + strlen(tmpdir_timestamp) + 1 + 3) > (sizeof(tmpdir) / sizeof(char))) { |