Tim Kientzle [Sun, 29 Nov 2009 23:09:46 +0000 (18:09 -0500)]
The fuzz tester uncovered an infinite loop in the recovery code that
searches forward for the next undamaged cpio header. This occurred
when the number of bytes returned by the next read operation happened
to be exactly the size of a cpio header. In this case, an off-by-one
error caused this code to decide that it didn't have enough bytes to
examine and then to loop around and ask for the exact same bytes again.
Tim Kientzle [Sun, 29 Nov 2009 20:35:13 +0000 (15:35 -0500)]
r1679 provides a way to gracefully handle the failure to decompress single ZISOFS entries; use that to suppress test failures in environments that lack zlib.
Tim Kientzle [Sun, 29 Nov 2009 20:33:21 +0000 (15:33 -0500)]
"Fix" this test on Win32 by suppressing tests of error handling that relies on proper error detection within archive_entry_update_pathname_utf8().
The core problem here is that Windows has several different APIs for character-set conversion. These tests rely on the POSIX-standard setlocale() to set the default character set for this process in order to then force character-conversion failures and verify the error-handling. But the Win32 APIs don't obey setlocale() so this fails. Indeed, I've found no way to programmatically override the CP_ACP code page for just the current process: I considered using CP_THREAD_ACP instead but it seems to be broken (or at least there are a lot of bloggers claiming it should never be used). It doesn't help that Windows documentation confuses "code page" with "language" (SetCurrentLocale() accepts a language code but the documentation claims it sets the code page while offering no insight into how language codes get mapped to code pages---remember that Japanese and Chinese are supported by several code pages). I've gleaned from various blogs that the default code page cannot be set to UTF-8 in any case due to some bad assumptions deep in Win32's character-conversion routines (this implies, of course, that there is a way to set the default code page, which I've not been able to find). From this, it appears that it's simply not possible to do the kind of testing I want to do here; if someone knows otherwise, please let me know.
Tim Kientzle [Sun, 29 Nov 2009 20:16:17 +0000 (15:16 -0500)]
Failure to decompress a single entry is not a FATAL problem (the entire archive is not dead), it's merely a FAILED problem (this entry is dead, but the rest of the archive may be readable).
Tim Kientzle [Thu, 19 Nov 2009 07:15:10 +0000 (02:15 -0500)]
Clang static analysis found an error return that was being
ignored. If copying data from an archive into a file on disk
fails with a fatal read error, exit with an error, since we
can't progress if the archive is broken. If it fails writing
to the file on disk, arrange for cpio to exit with an error.
Rename 'copy_data' to 'extract_data' to make it clearer that
it's only used when extracting data to disk.
Thanks to Michihiro NAKAJIMA for performing the analysis and fixing
most of the issues found.
Brad King [Wed, 18 Nov 2009 14:15:28 +0000 (09:15 -0500)]
Use _CrtSetReportMode only where available
We test for this function in <crtdbg.h> at CMake configuration time and
store the result as a HAVE__CrtSetReportMode configuration macro. We
need not perform the test for an autotools build because it supports no
platform that provides the function and the macro will be undefined.
Brad King [Wed, 18 Nov 2009 14:14:18 +0000 (09:14 -0500)]
Use ADD_TEST_28 macro to fix tests with the VS IDE
This macro simplifies creation of tests that refer to executables built
in the project. We can pass executables as arguments to a test using a
CMake 2.8 "generator expression" of the form "$<TARGET_FILE:myexe>".
The macro translates the arguments into something CMake 2.6 understands.
This change also fixes the tests so that they run correctly in build
trees created for multi-configuration build tools like the VS IDE.
These tools place executables in a per-configuration subdirectory so
references to executables in test arguments must use a test-time
substitution. The ADD_TEST_28 macro handles this automatically.
Brad King [Wed, 18 Nov 2009 14:14:08 +0000 (09:14 -0500)]
Create ADD_TEST_28 macro to approximate CMake 2.8
CMake 2.8 provides a new ADD_TEST(NAME) signature that simplifies
creation of tests that refer to executables built in the project. We
create an ADD_TEST_28 macro to approximate the new signature but work
with CMake 2.6.
Brad King [Wed, 18 Nov 2009 14:14:00 +0000 (09:14 -0500)]
Require CMake 2.6.3 or higher
Previously we required CMake 2.6.1 or higher, but CMake 2.6.3 provides
component-wise VERSION_LESS, VERSION_GREATER, and VERSION_EQUAL tests in
the if() command and the CMAKE_VERSION variable. Once the running CMake
is known to be 2.6.3 or higher, tests against its version are simple.
We also use the FATAL_ERROR option to CMAKE_MINIMUM_REQUIRED() to ensure
that CMake 2.4 gives up with an error immediately.
Brad King [Mon, 16 Nov 2009 16:29:46 +0000 (11:29 -0500)]
Add try-compile for 'major'
We define MAJOR_IN_MKDEV and MAJOR_IN_SYSMACROS from CMake by checking
sys/mkdev.h and sys/sysmacros.h for 'major'. Previously these macros
were left unconfigured for CMake builds.
Brad King [Mon, 16 Nov 2009 16:29:40 +0000 (11:29 -0500)]
Include test.h first in test main.c sources
This change makes the main.c source for each test executable consistent
with the other test sources. It also ensures that config.h (through
test.h) is included before system headers, thus configuring system
header feature macros correctly.
Brad King [Mon, 16 Nov 2009 16:29:18 +0000 (11:29 -0500)]
Initialize passwd/group lookup result
The "result" argument to functions get(pwu|grg)id_r and get(pw|gr)name_r
does not appear in the signatures provided on older platforms. We set
the pointer to the result memory in case the function ignores it, thus
ensuring initialization.
Brad King [Mon, 16 Nov 2009 16:28:59 +0000 (11:28 -0500)]
Extract ACL octal digit using mask of type 'int'
In archive_read_support_format_tar.c we mask a mode with ~0777777 to
erase the non-ACL octal digits. The mode is represented by int64_t so
the compiler sign-extends the our literal mask from type int to int64_t
for application of the & operator.
Unfortunately the resulting int64_t type is not allowed in switch() on
some old compilers (like HP). Since we are looking only for values that
fit in an int after the mask anyway, we might as well cast to int for
the entire mask operation. This also avoids depending on the compiler
to preserve the intention of the mask with sign-extension, making the
code easier to understand anyway.
Brad King [Mon, 16 Nov 2009 16:28:51 +0000 (11:28 -0500)]
Simplify try-compile for SIZE_MAX
This constant may be defined in one of a few headers that we always
include anyway. It is simpler and more reliable to look for the
constant in all the possible headers at once. Otherwise we would need
to store the result for each header in a separate cache entry.
Tim Kientzle [Fri, 13 Nov 2009 06:27:46 +0000 (01:27 -0500)]
Work around a compiler warning pointed out by Bill Hoffman.
Also, clean up the whitespace here to match the BSD style
that's used in the rest of libarchive.
Brad King [Wed, 11 Nov 2009 17:13:34 +0000 (12:13 -0500)]
Fix Borland integer constants
Some versions of Borland provide <stdint.h>, so we use it when possible.
However, the 64-bit signed and unsigned integer min/max constants cause
overflow warnings from Borland itself! For these constants we fall back
on our default definitions.
Brad King [Wed, 11 Nov 2009 14:20:26 +0000 (09:20 -0500)]
Use ARCHIVE_ERRNO_FILE_FORMAT instead of EILSEQ
We define ARCHIVE_ERRNO_FILE_FORMAT in "archive_platform.h" for
compatibility with platforms that do not have EILSEQ. Therefore we
should use it in "archive_write_set_format_pax.c".
Brad King [Wed, 11 Nov 2009 14:20:14 +0000 (09:20 -0500)]
Fix size_t and ssize_t defaults on Borland
We use more generic decision tests to select these types. The new tests
choose the proper types for Borland while preserving reasonable defaults
for other compilers.
Brad King [Wed, 11 Nov 2009 14:20:01 +0000 (09:20 -0500)]
Select stdint.h or inttypes.h in archive.h
Since archive.h cannot use try-compile results it must memorize the
availability of integer type headers for every platform. We split the
decision of which header to use out from the actual #include line by
defining __LA_STDINT_H to the chosen header.
Brad King [Wed, 11 Nov 2009 14:19:55 +0000 (09:19 -0500)]
Do not redefine stat and file mode macros
Some windows compilers define macros like O_RDONLY and S_ISBLK with
leading underscores (e.g. _O_RDONLY and _S_ISBLK). In our windows
compatibility header "archive_windows.h" we define the non-prefixed
names so that the rest of our code can use them everywhere. However,
some windows compilers also define the non-prefixed names. On these
compilers we should not redefine them.
Brad King [Wed, 11 Nov 2009 14:19:34 +0000 (09:19 -0500)]
Use macro for 64-bit integer literal suffixes
Some compilers, such as Borland and VS 6, define __int64 instead of the
more standard long long. Integer literals of type __int64 use the
suffix 'i64' instead of 'll'. We define the helper macros
ARCHIVE_LITERAL_LL(n)
ARCHIVE_LITERAL_ULL(n)
for 'long long' and 'unsigned long long' literals. The macros use the
proper suffix for the current compiler.
Brad King [Wed, 11 Nov 2009 14:19:19 +0000 (09:19 -0500)]
Fix wincrypt.h inclusion on VS 6
The VS 6 version of wincrypt.h only works if _WIN32_WINNT >= 0x0400.
We block its inclusion through windows.h by defining NOCRYPT, and then
define _WIN32_WINNT and include it only when necessary.
- Value stored to 'ret' is never read.
- Value stored to 'cpio' is never read.
- Although the value stored to 'v' is used in the enclosing expression,
the value is never actually read from 'v'.
- Value stored to 'line' is never read.
- Value stored to 'h' is never read.
- Value stored to 'old_entry' during its initialization is never read.
- Value stored to 'dest' is never read.
Tim Kientzle [Sun, 8 Nov 2009 07:06:02 +0000 (02:06 -0500)]
Thanks to Xavier for pointing out that the security.capability xattr
on Linux must be restored last. Let's try moving xattr restore to
after file data and see if that works any better; we may end up having
to do a full xattr restore both before and after the file data.
This also changes the behavior of xattr restore failures; they now
cause warnings when the entry is finished (which can be as late as
archive_write_close()) rather than when the header is written.
Tim Kientzle [Sun, 8 Nov 2009 02:33:34 +0000 (21:33 -0500)]
Be a little more careful about identifying mdoc-format manpages.
In particular, I recently had the update script pick up and try
to convert libarchive.so.5. Ouch.
Tim Kientzle [Sat, 7 Nov 2009 23:35:18 +0000 (18:35 -0500)]
Make the CTest integration simpler and a little more robust
by just reading list.h directly into cmake. This only requires
a suitable "DEFINE_TEST" macro.