0
0
mirror of https://github.com/libarchive/libarchive.git synced 2026-01-18 17:11:25 +01:00

804 Commits

Author SHA1 Message Date
Martin Matuška
b2d68e2f1a Merge pull request #2813 from AZero13/memcpy
We copy from p, not p + module_len
2025-12-26 10:22:13 +01:00
AZero13
e75e5892fd We copy from p, not p + module_len 2025-12-16 21:41:05 -05:00
AZero13
784b778f3b Fix p == null copy paste error 2025-12-16 21:37:16 -05:00
Martin Matuska
cfb02de558 tar: fix off-bounds read resulting from #2787 (3150539ed) 2025-12-09 22:40:42 +01:00
Tim Kientzle
81bc00a549 Merge pull request #2787 from ljdarj/aar
Fix bsdtar zero-length pattern issue.
2025-11-20 21:40:17 -08:00
ARJANEN Loïc Jean David
3150539edb Fix bsdtar zero-length pattern issue.
Uses the sed-like way (and Java-like, and .Net-like, and Javascript-like…) to fix this issue of advancing the string to be processed by one if the match is zero-length.

Fixes libarchive/libarchive#2725 and solves libarchive/libarchive#2438.
2025-11-21 00:44:38 +01:00
Martin Matuška
2caee6a37e Merge pull request #2752 from KlaraSystems/des/safe-writes-umask
Set umask before testing safe writes
2025-11-17 20:26:35 +01:00
AZero13
45a873e998 Bounds check newdir_len
Honestly, this is of little consequence; if old_len is too big the program will crash anyway. However, an error exists just in case.
2025-11-04 19:02:08 -05:00
Dag-Erling Smørgrav
7976476c9f Set umask before testing safe writes
Fixes:		27588eba50 ("Fix replacing a regular file with a dir for ARCHIVE_EXTRACT_SAFE_WRITES")
2025-10-13 21:49:29 +02: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
Martin Matuška
52db141ece Merge pull request #2477 from jrtc27/safe-dir-over-reg
Fix replacing a regular file with a dir for ARCHIVE_EXTRACT_SAFE_WRITES
2025-09-10 10:40:44 +02:00
Martin Matuška
6bd863f612 Merge pull request #2710 from meecash/CVE-2025-25724-check_strftime_result
Fix CVE-2025-25724 by checking the result of the strftime
2025-09-10 10:22:58 +02:00
Chris Brown
37ab51c2d3 address review comment 2025-08-22 04:00:44 -04:00
Chris Brown
466a2b5c7b fix test 2025-08-09 15:50:45 -04:00
Chris Brown
8b3d3ee99b update test 2025-08-08 20:40:14 -04:00
Chris Brown
fb859e6d3f add test 2025-08-08 20:15:35 -04:00
Marcin Mikula
ecce46744f Fix CVE-2025-25724 by checking the result of the strftime
to avoid use of undefined content of buf, in case when custom
locale makes the result string longer than buf length.

Signed-off-by: Marcin Mikula <marcin@helix.pl>
2025-07-30 10:33:51 +02:00
Tim Kientzle
ee49ac8106 Merge pull request #2687 from hemant-jadhav-emerson/master
Supress restrict keyword for msc_ver older than 1927
2025-06-28 19:04:30 -07:00
Dustin Howett
50d44b4202 win32: shim wopen, and make both open/wopen use _s "secure" variant
The new `__la_wopen` wrapper is a copy of `__la_open` that
expects--rather than converts--a wcs parameter.

The `sopen` variants are offered as "more secure" variants of `open` and
`wopen`; I cannot vouch for their security, but some build systems are
strict about the use of "banned insecure APIs".

I've confirmed that `_wsopen_s` and `_open_s` are present in the Windows
Vista SDK.

I did not confirm that they are available in the Windows XP Platform
SDK, in part because in e61afbd463 (2016!) Tim says:

> I'd like to completely remove support for WinXP and earlier.
2025-06-26 10:56:33 -07:00
Hemant
664a20b6c7 Error related to restrict keyword supressed for older vs compiler 2025-06-18 14:05:23 -05:00
Hemant
b7066d4a6b Error related to restrict keyword supressed for older vs compiler 2025-06-18 13:51:00 -05: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
65d0393f24 test_list_item: Do not modify LC_TIME
Test cases already get a C locale, which is sufficient for this test.
IF LC_TIME was not previously set, the used en_US.UTF-8 would stay
as an environment variable, possibly affecting other test cases.
Since en_US.UTF-8 is not guaranteed to be available, C is a better
choice.

Fixes https://github.com/libarchive/libarchive/issues/2560

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-30 17:33:19 +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
Tim Kientzle
fc4964751f Merge pull request #2609 from stoeckmann/safe_fprintf
tar: Handle more edge cases in safe_fprintf
2025-05-17 11:46:32 -07:00
Tobias Stoeckmann
c2d06848ea tar: Make safe_fprintf more platform independent
If vsnprintf fails with errno EOVERFLOW, the results are very platform
dependent but never useful. The implementation in glibc fills bytes with
blanks, FreeBSD fills them with zeros, OpenBSD and Windows set first
byte to '\0'.

Just stop processing and don't print anything, which makes it follow
the OpenBSD and Windows approach.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-17 00:23:01 +02:00
Tobias Stoeckmann
f3f2aaf0ac tar: Fix safe_fprintf comment
The stack buffer is never used for out of memory messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-17 00:23:01 +02:00
Tobias Stoeckmann
d1a260932c tar: Support large strings in safe_fprintf
The vsnprintf calls might return INT_MAX with very long strings.
Prevent a signed integer overflow when taking an additional nul
byte into account.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-17 00:23:00 +02:00
Tobias Stoeckmann
0e15b864c1 tar: Always use correct length in safe_fprintf
If the format buffer shall not be further increased in size, the
length value mistakenly takes the terminating nul byte into account.

This is in contrast to a successful vsnprintf call.

Also use the correct string length if fallback to stack buffer is
required.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-17 00:22:15 +02:00
Tobias Stoeckmann
3f1e45d146 tar: Clear safe_fprintf stack before usage
The stack buffer is never cleared, which can become an issue depending
on vsnprintf implementation's behavior if -1 is returned. The code
would eventually fall back to stack buffer which might be not
nul terminated.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-05-16 23:50:27 +02:00
Zhaofeng Li
00d559e4b9 bsdtar: Disallow multiple --files-from/-T options 2025-05-16 11:35:36 -06:00
Zhaofeng Li
c26f037745 bsdtar: Support --mtime and --clamp-mtime (#2601)
Hi,

This PR adds support for setting a forced mtime on all written files
(`--mtime` and `--clamp-mtime`) in bsdtar.

The end goal will be to support all functionalities in
<https://reproducible-builds.org/docs/archives/#full-example>, namely
`--sort` and disabling other attributes (atime, ctime, etc.).

Fixes #971.

## History

- [v1](https://github.com/zhaofengli/libarchive/tree/forced-mtime-v1):
Added `archive_read_disk_set_forced_mtime` in libarchive. As a result,
it was only applied when reading from the filesystem and not from other
archives.
- [v2](https://github.com/zhaofengli/libarchive/tree/forced-mtime-v2):
Refactored to apply the forced mtime in `archive_write`.
- v3 (current): Reduced libarchive change to exposing
`archive_parse_date`, moved clamping logic into bsdtar.

---------

Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
Co-authored-by: Dustin L. Howett <dustin@howett.net>
2025-05-15 14:08:14 +02:00
Moroshima
293c8bb992 correct only modes of --no-mac-metadata in bsdtar.1 (#2597)
`--no-mac-metadata` is c, r, u and x mode only
2025-05-15 12:59:37 +02:00
AZero13
b50b8a42f6 safe_printf should annotate with restrict (#2605)
printf has restrict for its parameters, and safe_printf should do the
same.
2025-05-14 18:24:54 -07:00
Graham Percival
f96497248e bsdtar: start "fake short equivalents" enum higher (#2586)
This avoids possible conflict with command-line options such as -B.
2025-04-14 11:39:14 -07:00
AZero13
da6bc7bf27 i should be size_t (#2575)
The size of i does not matter, and a size_t is added to it, so to avoid
that truncation, just make i size_t. It also is passed as a size_t.
2025-04-10 20:14:55 -07:00
Graham Percival
b580147278 Fix #endif comments for header guards (#2567) 2025-04-06 14:16:24 -07:00
Tobias Stoeckmann
a88e09a370 Remove extra newline from error messages (#2541)
The lafe_errc function adds a newline by itself already, so do not
insert one into the message.

You can reproduce with the following commands:

```
touch archive.tar
bsdtar -xf archive.tar -C /non-existing
```

```
bsdtar --exclude ""
```

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-03-16 15:33:05 -07:00
Peter Kästle
c9bc934e7e fix CVE-2025-1632 and CVE-2025-25724 (#2532)
Hi,

please find my approach to fix the CVE-2025-1632 and CVE-2025-25724
vulnerabilities in this pr.
As both error cases did trigger a NULL pointer deref (and triggered
hopefully everywhere a coredump), we can safely replace the actual
information by a predefined invalid string without breaking any
functionality.

---------

Signed-off-by: Peter Kaestle <peter@piie.net>
2025-03-10 08:43:04 -07:00
Tim Kientzle
3512329ba9 Avoid unreachable code in this test (#2528)
As remarked in #2521, this test has unreachable code on Windows, which
triggers a build failure in development due to warnings-as-errors.
(Release versions should not have warnings-as-errors.)
2025-03-01 09:06:31 -08:00
Jessica Clarke
27588eba50 Fix replacing a regular file with a dir for ARCHIVE_EXTRACT_SAFE_WRITES
The outer if checks !S_ISDIR(a->st.st_mode), so we know that the file
being overwritten is not a directory, and thus we can rename(2) over it
if we want to, but whether we can use a temporary regular file is a
property of the file being extracted. Otherwise, when replacing a
regular file with a directory, we end up in this case and create a
temporary regular file for the new directory, but with the permissions
of the directory (which likely includes x), and rename it over the top
at the end. Depending on where the archive_entry came from, it may have
a non-zero size that also isn't ovewritten with 0 (e.g. if it came from
stat(2)) and so the API user may then try to copy data (thus failing if
read(2) of directories isn't permitted, or writing the raw directory
contents if it is), but if the size is zero as is the case for this tar
test then it will end up not writing any data and "successfully"
overwrite the file with an empty file, not a directory.
2025-01-07 20:59:09 +00:00
Graham Percival
edcae6c164 Fix compiler nitpicks (#2465) 2024-12-30 08:30:42 -08:00
Graham Percival
4ce9c2f4be Add more casts for %c, %o, and %x (#2463) 2024-12-29 10:20:24 -08:00
Graham Percival
a659a44a85 Fix format strings (#2457) 2024-12-28 11:03:17 -08:00
Graham Percival
b557c1f161 Add tar/test/test_list_item (#2454) 2024-12-28 11:01:19 -08:00
Stephane Chazelas
4d5106f2b5 tar: fix bug when -s/a/b/ used more than once with b flag (#2435)
When the -s/regexp/replacement/ option was used with the b flag more
than once, the result of the previous substitution was appended to the
previous subject instead of replacing it. Fixed it by making sure the
subject is made the empty string before the call to realloc_strcat().
That in effect makes it more like a realloc_strcpy(), but creating a new
realloc_strcpy() function for that one usage doesn't feel worth it.

Resolves Issue libarchive/libarchive#2414

Co-authored-by: Stephane Chazelas <stephane@chazelas.org>
2024-12-27 15:20:16 -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
Graham Percival
0acaa2994a Fix remaining TODOs in test_stdio.c (#2444) 2024-12-27 12:38:03 -08:00
Graham Percival
72bbf9ec25 Fix some TODOs in tar/test/test_stdio.c (#2442) 2024-12-19 14:24:57 -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