Important Bugfixes:
  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

Obtained from:		libarchive
Libarchive commit:	ba80276ccc3c941c4918ec6e2460059f0c525c43
Libarcive tag:		v3.6.2
This commit is contained in:
Martin Matuska 2022-12-09 17:26:30 +01:00
parent 91ee6b45e4
commit b5a00e61e9
78 changed files with 800 additions and 247 deletions

View File

@ -10,11 +10,9 @@ FreeBSD_task:
BS: cmake
matrix:
freebsd_instance:
image_family: freebsd-13-0
image_family: freebsd-13-1
freebsd_instance:
image_family: freebsd-12-2
freebsd_instance:
image_family: freebsd-11-4
image_family: freebsd-12-3
prepare_script:
- ./build/ci/cirrus_ci/ci.sh prepare
configure_script:

View File

@ -4,7 +4,7 @@ on: [push, pull_request]
jobs:
MacOS:
runs-on: macos-latest
runs-on: macos-12
strategy:
matrix:
bs: [autotools, cmake]
@ -43,7 +43,7 @@ jobs:
path: libarchive.tar.xz
Ubuntu:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
bs: [autotools, cmake]
@ -83,7 +83,7 @@ jobs:
name: libarchive-ubuntu-${{ matrix.bs }}-${{ matrix.crypto }}-${{ github.sha }}
path: libarchive.tar.xz
Ubuntu-distcheck:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@master
- name: Install dependencies

41
.github/workflows/codeql.yml vendored Normal file
View File

@ -0,0 +1,41 @@
name: "CodeQL"
on:
push:
branches: [ "master", "3.5" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: "49 4 * * 2"
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ cpp ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
queries: +security-and-quality
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{ matrix.language }}"

View File

@ -213,7 +213,7 @@ OPTION(ENABLE_BZip2 "Enable the use of the system BZip2 library if found" ON)
OPTION(ENABLE_LIBXML2 "Enable the use of the system libxml2 library if found" ON)
OPTION(ENABLE_EXPAT "Enable the use of the system EXPAT library if found" ON)
OPTION(ENABLE_PCREPOSIX "Enable the use of the system PCREPOSIX library if found" ON)
OPTION(ENABLE_LibGCC "Enable the use of the system LibGCC library if found" ON)
OPTION(ENABLE_LIBGCC "Enable the use of the system LibGCC library if found" ON)
# CNG is used for encrypt/decrypt Zip archives on Windows.
OPTION(ENABLE_CNG "Enable the use of CNG(Crypto Next Generation)" ON)
@ -232,7 +232,7 @@ OPTION(ENABLE_INSTALL "Enable installing of libraries" ON)
SET(POSIX_REGEX_LIB "AUTO" CACHE STRING "Choose what library should provide POSIX regular expression support")
SET(ENABLE_SAFESEH "AUTO" CACHE STRING "Enable use of /SAFESEH linker flag (MSVC only)")
SET(WINDOWS_VERSION "WIN7" CACHE STRING "Set Windows version to use (Windows only)")
SET(WINDOWS_VERSION "WIN10" CACHE STRING "Set Windows version to use (Windows only)")
IF(ENABLE_COVERAGE)
include(LibarchiveCodeCoverage)
@ -243,7 +243,11 @@ IF(ENABLE_TEST)
ENDIF(ENABLE_TEST)
IF(WIN32)
IF(WINDOWS_VERSION STREQUAL "WIN8")
IF(WINDOWS_VERSION STREQUAL "WIN10")
SET(NTDDI_VERSION 0x0A000000)
SET(_WIN32_WINNT 0x0A00)
SET(WINVER 0x0A00)
ELSEIF(WINDOWS_VERSION STREQUAL "WIN8")
SET(NTDDI_VERSION 0x06020000)
SET(_WIN32_WINNT 0x0602)
SET(WINVER 0x0602)
@ -267,12 +271,12 @@ IF(WIN32)
SET(NTDDI_VERSION 0x05010000)
SET(_WIN32_WINNT 0x0501)
SET(WINVER 0x0501)
ELSE(WINDOWS_VERSION STREQUAL "WIN8")
ELSE(WINDOWS_VERSION STREQUAL "WIN10")
# Default to Windows Server 2003 API if we don't recognize the specifier
SET(NTDDI_VERSION 0x05020000)
SET(_WIN32_WINNT 0x0502)
SET(WINVER 0x0502)
ENDIF(WINDOWS_VERSION STREQUAL "WIN8")
ENDIF(WINDOWS_VERSION STREQUAL "WIN10")
ENDIF(WIN32)
IF(MSVC)
@ -610,8 +614,13 @@ IF(ENABLE_ZSTD)
SET(ZSTD_FIND_QUIETLY TRUE)
ENDIF (ZSTD_INCLUDE_DIR)
FIND_PATH(ZSTD_INCLUDE_DIR zstd.h)
FIND_LIBRARY(ZSTD_LIBRARY NAMES zstd libzstd)
IF(UNIX)
FIND_PACKAGE(PkgConfig QUIET)
PKG_SEARCH_MODULE(PC_ZSTD libzstd)
ENDIF()
FIND_PATH(ZSTD_INCLUDE_DIR zstd.h HINTS ${PC_ZSTD_INCLUDEDIR} ${PC_ZSTD_INCLUDE_DIRS})
FIND_LIBRARY(ZSTD_LIBRARY NAMES zstd libzstd HINTS ${PC_ZSTD_LIBDIR} ${PC_ZSTD_LIBRARY_DIRS})
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZSTD DEFAULT_MSG ZSTD_LIBRARY ZSTD_INCLUDE_DIR)
ELSE(ENABLE_ZSTD)
@ -1255,9 +1264,10 @@ IF(NOT FOUND_POSIX_REGEX_LIB AND POSIX_REGEX_LIB MATCHES "^(AUTO|LIBPCREPOSIX)$"
#
# If requested, try finding library for PCREPOSIX
#
IF(ENABLE_LibGCC)
FIND_PACKAGE(LibGCC)
IF(ENABLE_LIBGCC)
FIND_PACKAGE(LIBGCC)
ELSE()
MESSAGE(FATAL_ERROR "libgcc not found.")
SET(LIBGCC_FOUND FALSE) # Override cached value
ENDIF()
IF(ENABLE_PCREPOSIX)
@ -2024,6 +2034,17 @@ CHECK_CRYPTO("MD5;RMD160;SHA1;SHA256;SHA512" LIBMD)
CHECK_CRYPTO_WIN("MD5;SHA1;SHA256;SHA384;SHA512")
# Check visibility annotations
SET(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
SET(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fvisibility=hidden -Werror")
CHECK_C_SOURCE_COMPILES("void __attribute__((visibility(\"default\"))) foo(void);
int main() { return 0; }" HAVE_VISIBILITY_ATTR)
IF (HAVE_VISIBILITY_ATTR)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
ADD_DEFINITIONS(-D__LIBARCHIVE_ENABLE_VISIBILITY)
ENDIF(HAVE_VISIBILITY_ATTR)
SET(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}")
# Generate "config.h" from "build/cmake/config.h.in"
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)

View File

@ -513,6 +513,7 @@ libarchive_test_SOURCES= \
libarchive/test/test_read_format_tar_empty_filename.c \
libarchive/test/test_read_format_tar_empty_with_gnulabel.c \
libarchive/test/test_read_format_tar_filename.c \
libarchive/test/test_read_format_tar_invalid_pax_size.c \
libarchive/test/test_read_format_tbz.c \
libarchive/test/test_read_format_tgz.c \
libarchive/test/test_read_format_tlz.c \
@ -905,6 +906,7 @@ libarchive_test_EXTRA_DIST=\
libarchive/test/test_read_format_tar_empty_with_gnulabel.tar.uu \
libarchive/test/test_read_format_tar_empty_pax.tar.Z.uu \
libarchive/test/test_read_format_tar_filename_koi8r.tar.Z.uu \
libarchive/test/test_read_format_tar_invalid_pax_size.tar.uu \
libarchive/test/test_read_format_ustar_filename_cp866.tar.Z.uu \
libarchive/test/test_read_format_ustar_filename_eucjp.tar.Z.uu \
libarchive/test/test_read_format_ustar_filename_koi8r.tar.Z.uu \

2
NEWS
View File

@ -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

View File

@ -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

View File

@ -2,6 +2,7 @@
SET ZLIB_VERSION=1.2.12
SET BZIP2_VERSION=1ea1ac188ad4b9cb662e3f8314673c63df95a589
SET XZ_VERSION=5.2.5
SET ZSTD_VERSION=1.5.2
IF NOT "%BE%"=="mingw-gcc" (
IF NOT "%BE%"=="msvc" (
ECHO Environment variable BE must be mingw-gcc or msvc
@ -43,6 +44,14 @@ IF "%1"=="deplibs" (
echo Unpacking xz-%XZ_VERSION%.zip
C:\windows\system32\tar.exe -x -f xz-%XZ_VERSION%.zip || EXIT /b 1
)
IF NOT EXIST zstd-%ZSTD_VERSION%.zip (
echo Downloading https://github.com/facebook/zstd/archive/refs/tags/v%ZSTD_VERSION%.zip
curl -L -o zstd-%ZSTD_VERSION%.zip https://github.com/facebook/zstd/archive/refs/tags/v%ZSTD_VERSION%.zip || EXIT /b 1
)
IF NOT EXIST zstd-%ZSTD_VERSION% (
echo Unpacking zstd-%ZSTD_VERSION%.zip
C:\windows\system32\tar.exe -x -f zstd-%ZSTD_VERSION%.zip || EXIT /b 1
)
CD zlib-%ZLIB_VERSION%
IF "%BE%"=="mingw-gcc" (
SET PATH=%MINGWPATH%
@ -82,16 +91,28 @@ IF "%1"=="deplibs" (
cmake --build . --target ALL_BUILD --config Release || EXIT /b 1
cmake --build . --target INSTALL --config Release || EXIT /b 1
)
CD ..
CD zstd-%ZSTD_VERSION%\build\cmake
IF "%BE%"=="mingw-gcc" (
SET PATH=%MINGWPATH%
cmake -G "MinGW Makefiles" -D CMAKE_BUILD_TYPE="Release" . || EXIT /b 1
mingw32-make || EXIT /b 1
mingw32-make install || EXIT /b 1
) ELSE IF "%BE%"=="msvc" (
cmake -G "Visual Studio 17 2022" -D CMAKE_BUILD_TYPE="Release" . || EXIT /b 1
cmake --build . --target ALL_BUILD --config Release || EXIT /b 1
cmake --build . --target INSTALL --config Release || EXIT /b 1
)
) ELSE IF "%1%"=="configure" (
IF "%BE%"=="mingw-gcc" (
SET PATH=%MINGWPATH%
MKDIR build_ci\cmake
CD build_ci\cmake
cmake -G "MinGW Makefiles" -D ZLIB_LIBRARY="C:/Program Files (x86)/zlib/lib/libzlibstatic.a" -D ZLIB_INCLUDE_DIR="C:/Program Files (x86)/zlib/include" -D BZIP2_LIBRARIES="C:/Program Files (x86)/bzip2/lib/libbz2_static.a" -D BZIP2_INCLUDE_DIR="C:/Program Files (x86)/bzip2/include" -D LIBLZMA_LIBRARY="C:/Program Files (x86)/xz/lib/liblzma.a" -D LIBLZMA_INCLUDE_DIR="C:/Program Files (x86)/xz/include" ..\.. || EXIT /b 1
cmake -G "MinGW Makefiles" -D ZLIB_LIBRARY="C:/Program Files (x86)/zlib/lib/libzlibstatic.a" -D ZLIB_INCLUDE_DIR="C:/Program Files (x86)/zlib/include" -D BZIP2_LIBRARIES="C:/Program Files (x86)/bzip2/lib/libbz2_static.a" -D BZIP2_INCLUDE_DIR="C:/Program Files (x86)/bzip2/include" -D LIBLZMA_LIBRARY="C:/Program Files (x86)/xz/lib/liblzma.a" -D LIBLZMA_INCLUDE_DIR="C:/Program Files (x86)/xz/include" -D ZSTD_LIBRARY="C:/Program Files (x86)/zstd/lib/libzstd.a" -D ZSTD_INCLUDE_DIR="C:/Program Files (x86)/zstd/include" ..\.. || EXIT /b 1
) ELSE IF "%BE%"=="msvc" (
MKDIR build_ci\cmake
CD build_ci\cmake
cmake -G "Visual Studio 17 2022" -D CMAKE_BUILD_TYPE="Release" -D ZLIB_LIBRARY="C:/Program Files (x86)/zlib/lib/zlibstatic.lib" -D ZLIB_INCLUDE_DIR="C:/Program Files (x86)/zlib/include" -D BZIP2_LIBRARIES="C:/Program Files (x86)/bzip2/lib/bz2_static.lib" -D BZIP2_INCLUDE_DIR="C:/Program Files (x86)/bzip2/include" -D LIBLZMA_LIBRARY="C:/Program Files (x86)/xz/lib/liblzma.lib" -D LIBLZMA_INCLUDE_DIR="C:/Program Files (x86)/xz/include" ..\.. || EXIT /b 1
cmake -G "Visual Studio 17 2022" -D CMAKE_BUILD_TYPE="Release" -D ZLIB_LIBRARY="C:/Program Files (x86)/zlib/lib/zlibstatic.lib" -D ZLIB_INCLUDE_DIR="C:/Program Files (x86)/zlib/include" -D BZIP2_LIBRARIES="C:/Program Files (x86)/bzip2/lib/bz2_static.lib" -D BZIP2_INCLUDE_DIR="C:/Program Files (x86)/bzip2/include" -D LIBLZMA_LIBRARY="C:/Program Files (x86)/xz/lib/liblzma.lib" -D LIBLZMA_INCLUDE_DIR="C:/Program Files (x86)/xz/include" -D ZSTD_LIBRARY="C:/Program Files (x86)/zstd/lib/zstd_static.lib" -D ZSTD_INCLUDE_DIR="C:/Program Files (x86)/zstd/include" ..\.. || EXIT /b 1
)
) ELSE IF "%1%"=="build" (
IF "%BE%"=="mingw-gcc" (

View File

@ -0,0 +1,22 @@
# - Find libgcc
# Find the libgcc library.
#
# LIBGCC_LIBRARIES - List of libraries when using libgcc
# LIBGCC_FOUND - True if libgcc found.
IF (LIBGCC_LIBRARY)
# Already in cache, be silent
SET(LIBGCC_FIND_QUIETLY TRUE)
ENDIF (LIBGCC_LIBRARY)
FIND_LIBRARY(LIBGCC_LIBRARY NAMES gcc libgcc)
# handle the QUIETLY and REQUIRED arguments and set LIBGCC_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBGCC DEFAULT_MSG LIBGCC_LIBRARY)
IF(LIBGCC_FOUND)
SET(LIBGCC_LIBRARIES ${LIBGCC_LIBRARY})
SET(HAVE_LIBGCC 1)
ENDIF(LIBGCC_FOUND)

View File

@ -316,13 +316,13 @@ typedef uint64_t uintmax_t;
#cmakedefine ARCHIVE_XATTR_LINUX 1
/* Version number of bsdcpio */
#cmakedefine BSDCPIO_VERSION_STRING "${BSDCPIO_VERSION_STRING}"
#cmakedefine BSDCPIO_VERSION_STRING "@BSDCPIO_VERSION_STRING@"
/* Version number of bsdtar */
#cmakedefine BSDTAR_VERSION_STRING "${BSDTAR_VERSION_STRING}"
#cmakedefine BSDTAR_VERSION_STRING "@BSDTAR_VERSION_STRING@"
/* Version number of bsdcat */
#cmakedefine BSDCAT_VERSION_STRING "${BSDCAT_VERSION_STRING}"
#cmakedefine BSDCAT_VERSION_STRING "@BSDCAT_VERSION_STRING@"
/* Define to 1 if you have the `acl_create_entry' function. */
#cmakedefine HAVE_ACL_CREATE_ENTRY 1
@ -1231,13 +1231,13 @@ typedef uint64_t uintmax_t;
#cmakedefine HAVE__MKGMTIME64 1
/* Define as const if the declaration of iconv() needs const. */
#define ICONV_CONST ${ICONV_CONST}
#define ICONV_CONST @ICONV_CONST@
/* Version number of libarchive as a single integer */
#cmakedefine LIBARCHIVE_VERSION_NUMBER "${LIBARCHIVE_VERSION_NUMBER}"
#cmakedefine LIBARCHIVE_VERSION_NUMBER "@LIBARCHIVE_VERSION_NUMBER@"
/* Version number of libarchive */
#cmakedefine LIBARCHIVE_VERSION_STRING "${LIBARCHIVE_VERSION_STRING}"
#cmakedefine LIBARCHIVE_VERSION_STRING "@LIBARCHIVE_VERSION_STRING@"
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
slash. */
@ -1255,7 +1255,7 @@ typedef uint64_t uintmax_t;
#cmakedefine NO_MINUS_C_MINUS_O 1
/* The size of `wchar_t', as computed by sizeof. */
#cmakedefine SIZEOF_WCHAR_T ${SIZEOF_WCHAR_T}
#cmakedefine SIZEOF_WCHAR_T @SIZEOF_WCHAR_T@
/* Define to 1 if strerror_r returns char *. */
#cmakedefine STRERROR_R_CHAR_P 1
@ -1291,59 +1291,59 @@ typedef uint64_t uintmax_t;
#endif /* SAFE_TO_DEFINE_EXTENSIONS */
/* Version number of package */
#cmakedefine VERSION "${VERSION}"
#cmakedefine VERSION "@VERSION@"
/* Number of bits in a file offset, on hosts where this is settable. */
#cmakedefine _FILE_OFFSET_BITS ${_FILE_OFFSET_BITS}
#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
#cmakedefine _LARGEFILE_SOURCE 1
/* Define for large files, on AIX-style hosts. */
#cmakedefine _LARGE_FILES ${_LARGE_FILES}
#cmakedefine _LARGE_FILES @_LARGE_FILES@
/* Define to control Windows SDK version */
#ifndef NTDDI_VERSION
#cmakedefine NTDDI_VERSION ${NTDDI_VERSION}
#cmakedefine NTDDI_VERSION @NTDDI_VERSION@
#endif // NTDDI_VERSION
#ifndef _WIN32_WINNT
#cmakedefine _WIN32_WINNT ${_WIN32_WINNT}
#cmakedefine _WIN32_WINNT @_WIN32_WINNT@
#endif // _WIN32_WINNT
#ifndef WINVER
#cmakedefine WINVER ${WINVER}
#cmakedefine WINVER @WINVER@
#endif // WINVER
/* Define to empty if `const' does not conform to ANSI C. */
#cmakedefine const ${const}
#cmakedefine const @const@
/* Define to `int' if <sys/types.h> doesn't define. */
#cmakedefine gid_t ${gid_t}
#cmakedefine gid_t @gid_t@
/* Define to `unsigned long' if <sys/types.h> does not define. */
#cmakedefine id_t ${id_t}
#cmakedefine id_t @id_t@
/* Define to `int' if <sys/types.h> does not define. */
#cmakedefine mode_t ${mode_t}
#cmakedefine mode_t @mode_t@
/* Define to `long long' if <sys/types.h> does not define. */
#cmakedefine off_t ${off_t}
#cmakedefine off_t @off_t@
/* Define to `int' if <sys/types.h> doesn't define. */
#cmakedefine pid_t ${pid_t}
#cmakedefine pid_t @pid_t@
/* Define to `unsigned int' if <sys/types.h> does not define. */
#cmakedefine size_t ${size_t}
#cmakedefine size_t @size_t@
/* Define to `int' if <sys/types.h> does not define. */
#cmakedefine ssize_t ${ssize_t}
#cmakedefine ssize_t @ssize_t@
/* Define to `int' if <sys/types.h> doesn't define. */
#cmakedefine uid_t ${uid_t}
#cmakedefine uid_t @uid_t@
/* Define to `int' if <sys/types.h> does not define. */
#cmakedefine intptr_t ${intptr_t}
#cmakedefine intptr_t @intptr_t@
/* Define to `unsigned int' if <sys/types.h> does not define. */
#cmakedefine uintptr_t ${uintptr_t}
#cmakedefine uintptr_t @uintptr_t@

View File

@ -10,3 +10,4 @@ Cflags: -I${includedir}
Cflags.private: -DLIBARCHIVE_STATIC
Libs: -L${libdir} -larchive
Libs.private: @LIBS@
Requires.private: @LIBSREQUIRED@

View File

@ -1 +1 @@
3006001
3006002

View File

@ -4,8 +4,8 @@ dnl First, define all of the version numbers up front.
dnl In particular, this allows the version macro to be used in AC_INIT
dnl These first two version numbers are updated automatically on each release.
m4_define([LIBARCHIVE_VERSION_S],[3.6.1])
m4_define([LIBARCHIVE_VERSION_N],[3006001])
m4_define([LIBARCHIVE_VERSION_S],[3.6.2])
m4_define([LIBARCHIVE_VERSION_N],[3006002])
dnl bsdtar and bsdcpio versioning tracks libarchive
m4_define([BSDTAR_VERSION_S],LIBARCHIVE_VERSION_S())
@ -378,6 +378,7 @@ if test "x$with_iconv" != "xno"; then
AC_CHECK_HEADERS([localcharset.h])
am_save_LIBS="$LIBS"
LIBS="${LIBS} ${LIBICONV}"
LIBSREQUIRED="$LIBSREQUIRED${LIBSREQUIRED:+ }iconv"
AC_CHECK_FUNCS([locale_charset])
LIBS="${am_save_LIBS}"
if test "x$ac_cv_func_locale_charset" != "xyes"; then
@ -1209,24 +1210,8 @@ fi
if test "x$with_openssl" != "xno"; then
AC_CHECK_HEADERS([openssl/evp.h])
saved_LIBS=$LIBS
case "$host_os" in
*mingw* | *cygwin* | *msys*)
case "$host_cpu" in
x86_64)
AC_CHECK_LIB(eay64,OPENSSL_config)
if test "x$ac_cv_lib_eay64_main" != "xyes"; then
AC_CHECK_LIB(eay32,OPENSSL_config)
fi
;;
*)
AC_CHECK_LIB(eay32,OPENSSL_config)
;;
esac
;;
*)
AC_CHECK_LIB(crypto,OPENSSL_config)
;;
esac
LIBSREQUIRED="$LIBSREQUIRED${LIBSREQUIRED:+ }libssl libcrypto"
AC_CHECK_LIB(crypto,OPENSSL_config)
CRYPTO_CHECK(MD5, OPENSSL, md5)
CRYPTO_CHECK(RMD160, OPENSSL, rmd160)
CRYPTO_CHECK(SHA1, OPENSSL, sha1)
@ -1236,6 +1221,8 @@ if test "x$with_openssl" != "xno"; then
AC_CHECK_FUNCS([PKCS5_PBKDF2_HMAC_SHA1])
fi
AC_SUBST(LIBSREQUIRED)
# Probe libmd AFTER OpenSSL/libcrypto.
# The two are incompatible and OpenSSL is more complete.
AC_CHECK_HEADERS([md5.h ripemd.h sha.h sha256.h sha512.h])
@ -1260,6 +1247,18 @@ case "$host_os" in
;;
esac
dnl Visibility annotations...
saved_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -fvisibility=hidden -Werror"
AC_MSG_CHECKING(whether compiler supports visibility annotations)
AC_LINK_IFELSE([AC_LANG_PROGRAM([
int foo( void ) __attribute__((visibility("default")));
])],
[CFLAGS="$saved_CFLAGS -fvisibility=hidden -D__LIBARCHIVE_ENABLE_VISIBILITY";
AC_MSG_RESULT(yes)],
[CFLAGS="$saved_CFLAGS"
AC_MSG_RESULT(no)])
# Ensure test directories are present if building out-of-tree
AC_CONFIG_COMMANDS([mkdirs],
[mkdir -p libarchive/test tar/test cat/test cpio/test])

View File

@ -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));

View File

@ -5,6 +5,10 @@
#
############################################
if (ANDROID)
include_directories(${PROJECT_SOURCE_DIR}/contrib/android/include)
endif()
# Public headers
SET(include_HEADERS
archive.h
@ -78,6 +82,7 @@ SET(libarchive_SOURCES
archive_read_set_format.c
archive_read_set_options.c
archive_read_support_filter_all.c
archive_read_support_filter_by_code.c
archive_read_support_filter_bzip2.c
archive_read_support_filter_compress.c
archive_read_support_filter_gzip.c

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -418,8 +418,9 @@ la_linkname_from_pathw(const wchar_t *path, wchar_t **outbuf, int *linktype)
FILE_FLAG_OPEN_REPARSE_POINT;
int ret;
h = CreateFileW(path, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, flag,
NULL);
h = CreateFileW(path, 0,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
OPEN_EXISTING, flag, NULL);
if (h == INVALID_HANDLE_VALUE) {
la_dosmaperr(GetLastError());
return (-1);
@ -1073,7 +1074,9 @@ next_entry(struct archive_read_disk *a, struct tree *t,
else
flags |= FILE_FLAG_SEQUENTIAL_SCAN;
t->entry_fh = CreateFileW(tree_current_access_path(t),
GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, flags, NULL);
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL, OPEN_EXISTING, flags, NULL);
if (t->entry_fh == INVALID_HANDLE_VALUE) {
la_dosmaperr(GetLastError());
archive_set_error(&a->archive, errno,
@ -2046,7 +2049,8 @@ tree_current_file_information(struct tree *t, BY_HANDLE_FILE_INFORMATION *st,
if (sim_lstat && tree_current_is_physical_link(t))
flag |= FILE_FLAG_OPEN_REPARSE_POINT;
h = CreateFileW(tree_current_access_path(t), 0, FILE_SHARE_READ, NULL,
h = CreateFileW(tree_current_access_path(t), 0,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
OPEN_EXISTING, flag, NULL);
if (h == INVALID_HANDLE_VALUE) {
la_dosmaperr(GetLastError());
@ -2275,7 +2279,8 @@ archive_read_disk_entry_from_file(struct archive *_a,
} else
desiredAccess = GENERIC_READ;
h = CreateFileW(path, desiredAccess, FILE_SHARE_READ, NULL,
h = CreateFileW(path, desiredAccess,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
OPEN_EXISTING, flag, NULL);
if (h == INVALID_HANDLE_VALUE) {
la_dosmaperr(GetLastError());
@ -2337,7 +2342,8 @@ archive_read_disk_entry_from_file(struct archive *_a,
if (fd >= 0) {
h = (HANDLE)_get_osfhandle(fd);
} else {
h = CreateFileW(path, GENERIC_READ, FILE_SHARE_READ, NULL,
h = CreateFileW(path, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (h == INVALID_HANDLE_VALUE) {
la_dosmaperr(GetLastError());

View File

@ -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,

View File

@ -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 */

View File

@ -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 */

View File

@ -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:

View File

@ -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);
}

View File

@ -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;

View File

@ -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:

View File

@ -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;

View File

@ -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);

View File

@ -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,

View File

@ -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;
}
@ -2108,6 +2107,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.

View File

@ -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,

View File

@ -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.

View File

@ -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;

View File

@ -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;

View File

@ -1370,6 +1370,7 @@ archive_write_disk_new(void)
free(a);
return (NULL);
}
a->path_safe.s[0] = 0;
return (&a->archive);
}
@ -2154,6 +2155,8 @@ check_symlinks(struct archive_write_disk *a)
return (ARCHIVE_FAILED);
}
}
if (!c)
break;
pn[0] = c;
pn++;
}
@ -2258,6 +2261,9 @@ cleanup_pathname(struct archive_write_disk *a, wchar_t *name)
return (ARCHIVE_FAILED);
} else
p += 4;
/* Network drive path like "\\<server-name>\<share-name>\file" */
} else if (p[0] == L'\\' && p[1] == L'\\') {
p += 2;
}
/* Skip leading drive letter from archives created

View File

@ -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

View File

@ -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");

View File

@ -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;

View File

@ -162,6 +162,7 @@ IF(ENABLE_TEST)
test_read_format_tar_empty_with_gnulabel.c
test_read_format_tar_empty_pax.c
test_read_format_tar_filename.c
test_read_format_tar_invalid_pax_size.c
test_read_format_tbz.c
test_read_format_tgz.c
test_read_format_tlz.c

View File

@ -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

View File

@ -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);

View File

@ -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)) {

View File

@ -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));
}

View File

@ -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));
}

View File

@ -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();
}
}
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();
}

View File

@ -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));
}

View File

@ -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

View File

@ -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",

View File

@ -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)

View File

@ -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));
}

View File

@ -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);

View File

@ -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));

View File

@ -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));

View File

@ -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));

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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));

View File

@ -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;

View File

@ -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)))

View File

@ -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;

View File

@ -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. */

View File

@ -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. */

View File

@ -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];

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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.

View File

@ -63,7 +63,7 @@ __FBSDID("$FreeBSD: src/usr.bin/tar/util.c,v 1.23 2008/12/15 06:00:25 kientzle E
#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 {

View File

@ -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))) {