510 Commits
Author SHA1 Message Date
Tim Kientzle 6ea9e10bc5 Merge pull request #3321 from carrerasdarren-cell/fix/cpio-newc-inode-synthesis
cpio: synthesize newc inode values
2026-08-10 06:58:16 -07:00
Darren Carreras 48fc018080 cpio: test synthetic newc inode values
Exercise large inode values that collide after 32-bit truncation,
hardlink identity, and distinct device IDs. Update bsdcpio expectations
so successful synthesis produces no truncation warnings.
2026-08-08 17:50:29 -04:00
datauwu efa19ce699 bsdcpio: fix UB signed overflow in time formatting
Use difftime() instead of subtracting time_t values when choosing the
date format. This avoids signed overflow for far past or future
timestamps without changing normal output.
2026-08-01 19:48:38 +08:00
Martin Matuška ba387256e0 Merge pull request #2918 from aale24/fix-test-format-newc-race
Fix test_format_newc timestamp race condition
2026-06-19 09:48:25 +02:00
Tobias Stoeckmann 6338754d6a cpio: Simplify WINAPI_FAMILIY_PARTITION check
The macro is defined in archive_windows.h if missing.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-03 20:51:04 +02:00
Tobias Stoeckmann 2a62d049ea tools: Handle archive_match errors
These functions can return negative values, in which case operation
itself failed. While internal libarchive libraries handle these cases,
the tools don't. Check for negative values in them as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:18:38 +02:00
Tim Kientzle f833d13e6d Fix CMake-based testing 2026-05-06 22:02:15 -07:00
Tim Kientzle 2f5ed45e4c [CMake] Automatically update list.h
`list.h` contains a list of all the tests and is generated
by grepping the test source files for `DEFINE_TEST`.
Previously, it was generated at configure time.
This meant that if you added a new test to an existing
source file, you had to manually reconfigure.

This adds the necessary dependencies so that `list.h`
is regenerated whenever any C test source changes.
This ensures that new tests are always discovered automatically.

Note:  If someone wants to update the autoconf-based
build system to do this, please send a PR.
2026-05-05 20:54:12 -07:00
Alejandro Perez 23de58817c Fix test_format_newc timestamp race condition
Add 1-second tolerance to timestamp assertion to account
for timing variations in containerized build environments.

Fixes #2917
2026-04-27 06:18:19 +00:00
Tobias Stoeckmann bf7cd8c284 Fix memory leaks in test suites
Release memory so ASAN becomes a viable option for test suites.
2026-04-20 20:12:18 +02:00
Tim Kientzle aaf154f627 Merge pull request #2922 from stoeckmann/err_style_followup
Improve style of more error messages
2026-04-12 15:02:13 -07:00
Tobias Stoeckmann 393d686854 cpio: Fix -R memory leak
If the -R command line argument is supplied with user/group names
multiple times, memory leaks occur.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-20 13:40:19 +01:00
Tobias Stoeckmann 53755dc951 Remove periods from error messages
Some error messages previously slipped through. Remove periods from
these messages as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-18 14:30:44 +01:00
Tobias Stoeckmann df9ce5cd6c cpio: Reduce visibility of variable buff
The buff variable is only used in entry_to_archive. Moving it into the
specific code block where it is actually used reduces its visibility and
thus makes it easier to read the code:

Since Windows indeed uses unsigned for read, this makes it much easier
to verify that buff never grows and cannot be too large.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-17 10:11:58 +01:00
Tim Kientzle 284a0a103f Merge pull request #2910 from stoeckmann/cpio_num
cpio: Check number arguments before casts
2026-03-16 06:56:31 -07:00
Tim Kientzle 9d1631752b Merge pull request #2909 from stoeckmann/lafe_error
tools: Remove `Error : ` prefix in lafe_errc calls
2026-03-16 06:47:14 -07:00
Tim Kientzle 339b0e7003 Merge pull request #2908 from stoeckmann/cpio_mode
cpio: Improve mode option handling
2026-03-16 06:46:38 -07:00
Tobias Stoeckmann 2f6e6b03ba cpio: Set lafe_warnc code to 0
Otherwise an unknown error is printed, which does not help the user
(especially since a custom message is printed in this case already).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 14:34:32 +01:00
Tobias Stoeckmann 71d8195f2e cpio: Check number arguments before casts
Make sure that supplied arguments actually fit into target data types.
Print an error if numbers are too large instead of silently truncating
them.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 14:19:30 +01:00
Tobias Stoeckmann c24fa12410 tools: Remove 'Error : ' prefix in lafe_errc calls
Only a minority of calls to lafe_errc state explicitly that an error
occurred. Remove these few cases for a more unified argument handling.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 14:01:56 +01:00
Tobias Stoeckmann 40e00705e5 cpio: Clarify that onyl one mode is acceptable
Do not print that at least one mode has to be supplied. Exactly one mode
has to be supplied instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 13:50:42 +01:00
Tobias Stoeckmann 72ebae391a cpio: Improve mode argument checks
Complain only if contradicting mode options are supplied. Passing the
same argument multiple times should not lead to errors.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 10:16:19 +01:00
Tobias Stoeckmann ef1744a352 cpio: Use getline in cpio_rename
The buffer has a fixed 1024 limit, which can be smaller than the maximum
allowed path length. Increasing the limit to 4096 would partially help,
but since leading spaces are stripped, input lines could be valid and
longer.

Use getline instead.
2026-03-16 09:43:54 +01:00
Tobias Stoeckmann 1ea5604e3e cpio: Refactor cpio_rename
Let cpio_rename work with the entry directly. In this initial step, it
moves buff into the stack.

The comment suggests that this was done in the past already.
2026-03-16 09:43:54 +01:00
Tobias Stoeckmann 31b48a1326 cpio: Cast int64_t to long long in printf
LLP64 systems like Windows 11 have a 32 bit long. Cast int64_t to
long long for better output.

Same is true for 32 bit systems.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-10 18:22:17 +01:00
Dag-Erling Smørgrav a252c60308 test_main: Run tests as unprivileged user
If run as root (as is the case in CI), switch to an unprivileged user
(default: nobody) before running each test, and switch back after.
This makes it possible to write tests that rely on file permissions.

Note that tests that use the UID or GID must now check the EUID / EGID
instead as they will be different while the test is running.  The only
way to avoid that is to run each test case in a child process, which
would hugely increase the complexity of test_run().
2026-03-02 12:42:05 +01:00
AZero13 55fbf225c8 uname_override checks gname_override when it should check uname_override 2025-12-16 21:44:31 -05:00
Tim Kientzle 96f76577d3 Rename err.h to avoid conflict with system header
Depending on header search path ordering, we can easily
confuse libarchive_fe/err.h with the system header.
Rename ours to lafe_err.h to avoid the confusion.
Rename libarchive_fe/err.c to match.
2025-09-13 12:30:03 -07:00
Tobias Stoeckmann 36bac92cd2 tools: Enforce default handling of SIGCHLD
Ignoring SIGCHLD gets passed to child processes. Doing that has
influence on waitpid, namely that zombie processes won't be
created. This means that a status can never be read.

We can't enforce this in library, but libarchive's tools can be
protected against this by enforcing default handling.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-02 23:29:49 +02:00
Tobias Stoeckmann 612223356e Prefer __CYGWIN__ over CYGWIN definition
The cygwin FAQ states that __CYGWIN__ is defined when building for a
Cygwin environment. Only a few test files check (inconsistently) for
CYGWIN, so adjust them to the recommended __CYGWIN__ definition.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-24 11:37:26 +02:00
Graham Percival b580147278 Fix #endif comments for header guards (#2567) 2025-04-06 14:16:24 -07:00
Silent 14b8803c40 Fix a Y2038 bug by replacing Int32x32To64 with regular multiplication (#2471)
`Int32x32To64` macro internally truncates the arguments to int32, while
`time_t` is 64-bit on most/all modern platforms. Therefore, usage of
this macro creates a Year 2038 bug.

I detailed this issue a while ago in a writeup, and spotted the same
issue in this repository when updating the list of affected
repositories:
<https://cookieplmonster.github.io/2022/02/17/year-2038-problem/>

A few more notes:
1. I changed all uses of `Int32x32To64` en masse, even though at least
one of them was technically OK and used with int32 parameters only. IMO
better safe than sorry.
2. This is untested, but it's a small enough change that I hope the CI
success is a good enough indicator.
2025-01-01 08:31:35 -08:00
Graham Percival 25c3d9afea Fix compiler nitpicks (#2470) 2024-12-30 19:42:04 -08:00
Graham Percival 982747fd66 Fix compiler nitpicks (#2469) 2024-12-30 13:31:48 -08:00
Graham Percival edcae6c164 Fix compiler nitpicks (#2465) 2024-12-30 08:30:42 -08:00
Graham Percival a659a44a85 Fix format strings (#2457) 2024-12-28 11:03:17 -08:00
Zeun 4ebca5ff83 Fix -Werror=warning error and wrap some INSTALL directives with an ENABLE_INSTALL guard (#2397)
1. Fixes build when compiling without ZLIB/BZIP/LZMA `char finishing`
2. All INSTALL directives are now guarded by ENABLE_INSTALL
2024-12-27 12:53:13 -08:00
Mostyn Bramley-Moore 8ac45a813e Report skipped tests to cmake/ctest (#2429)
This plumbing is required for cmake/ctest to recognise and report
skipped tests.

Now skipped tests in cmake ci jobs are reported like so:
```
          Start   7: libarchive_test_acl_platform_posix1e_read
    7/785 Test   #7: libarchive_test_acl_platform_posix1e_read ................................***Skipped   0.02 sec
```

And there is a list of skipped tests shown at the end of the test run.
2024-12-08 18:07:49 -08:00
Martin Matuška d8c3b97b31 tests: use const char instead of char in one case (#2381)
Found in test_extract_cpio_absolute_paths.c when compiling FreeBSD base
2024-10-13 13:41:06 -07:00
Emil Velikov 6287b99eb7 Convert the tools and respective tests to SPDX (#2317)
This is the first part of converting the project to use SPDX license
identifiers instead using the verbose license text.

The patches are semi-automated and I've went through manually to ensure
no license changes were made. That said, I would welcome another pair of
eyes, since I am only human.

See https://github.com/libarchive/libarchive/issues/2298

---------

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2024-10-12 20:54:16 -07:00
Mostyn Bramley-Moore a65f765f17 bsdcpio should exit with an error code if an entry can't be extracted (#2371)
For example if --insecure is not specified, and one of the security
checks fails.
2024-10-07 08:51:17 -07:00
Mostyn Bramley-Moore 62ce582d1c Simplify tests added in #2363, use testworkdir (#2369) 2024-10-06 20:34:58 -07:00
Dag-Erling Smørgrav a90e9d84ec Miscellaneous code cleanup (#2285)
This fixes various code quality issues I encountered while chasing a
memory leak reported by test automation. I failed to reproduce the
memory leak, but I hope you find this useful nonetheless.
2024-10-04 08:45:58 -07:00
Mostyn Bramley-Moore 2fd35b0fdb Fix ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS on windows (#2363) 2024-10-04 08:36:56 -07:00
Tim Kientzle 3fdf9bf80f Fix potential overflow warning in cpio test_option_t (#2250)
Fixes an error from #2237.
2024-06-19 16:18:35 -07:00
Tim Kientzle 13c710a825 [cpio test] Dates can be more than 12 bytes, depending on the locale (#2237)
In order to match cpio output, format the reference date with _at least_
12 bytes instead of _exactly_ 12 bytes. This should fix a gratuitous
test failure on certain systems that default to multi-byte locales.
2024-06-16 20:23:11 -07:00
Martin MatuškaandRose 826c0afe19 Resolve TODO: Return uname and gname overrides (#2141)
Simplify introducing a struct cpio_owner

Co-authored-by: Rose <83477269+AtariDreams@users.noreply.github.com>
2024-05-13 08:44:28 +02:00
Tobias StoeckmannandDuncan Horn 3085a3e9d3 [Windows] Fix test compilation warnings with Visual Studio (#2178)
Fixes all test-related compiler warnings with Visual Studio 2022 on
Windows 11.

Contains some changes from
https://github.com/libarchive/libarchive/pull/2095.

CC: @dunhor

---------

Co-authored-by: Duncan Horn <dunhor@microsoft.com>
2024-05-12 12:26:19 -07:00
Tobias Stoeckmann bd974e1b7b tools: Fix stack overflow with many arguments (#2122)
Supplying a lot of "-" arguments to tools can lead to stack overflow due
to recursive *_getopt function calls.

Proof of Concept:

1. Compile libarchive with Visual Studio 2022
2. Call bsdtar with insane amount of arguments
```
PS> bsdtar.exe ("- "*10000).split(" ")
```
The event log shows that bsdtar.exe failed with `0xc00000fd` (stack
overflow).

If compiled with gcc, this does not happen by default because the code
is internally optimized to use this suggested loop instead. You have to
compile with CFLAGS="-O0" to provoke it with gcc as well.
2024-04-12 22:15:53 -07:00
Emil Velikov d5713db2d4 Minor __LA_NORETURN inspired fixes (#2028)
Earlier MR https://github.com/libarchive/libarchive/pull/2000 forgot to
annotate some functions as __LA_NORETURN. While fixing that I've noticed
that the bsdcat.h header could use some fixes so I've snuck those in.

Kind of make sense to group in one PR, but can split people prefer so.

/cc @AtariDreams fyi

---------

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2023-12-07 19:22:27 -08:00