3396 Commits

Author SHA1 Message Date
Paul Eggert
8fca6143ea maint: pacify -Wzero-as-null-pointer-constant
Recent Gnulib enables this warning, and it did find a bug
in GNU Tar, so pacify GCC everywhere else by preferring
NULL to 0 for pointers.
2026-01-23 17:38:38 -08:00
Paul Eggert
29bb75ed65 Fix EOF return from wordsplit_finish
* lib/wordsplit.c (wordsplit_finish):
Fix typo caught by -Wzero-as-null-pointer-constant
2026-01-23 17:38:38 -08:00
Paul Eggert
bd20771003 Sync bootstrap from gnulib 2026-01-23 17:38:38 -08:00
Paul Eggert
f1efd80ebe build: update gnulib and paxutils submodules to latest
* src/extract.c: Include issymlinkat.h, not issymlink.h.
2026-01-23 17:38:38 -08:00
Paul Eggert
d55c5fd2c5 Update copyright years
UPDATE_COPYRIGHT_USE_INTERVALS=1 \
$HOME/src/gnu/gnulib/build-aux/update-copyright \
  $(git ls-files | sed -e '/^gnulib$/d
			   /^paxutils$/d
			   /^COPYING$/d
			   /\/fdl.texi$/d')
sed -i '2000,${
    /^Copyright @copyright/d
    s/^[0-9]*--\(2026 Free Software Foundation, Inc.\)/Copyright (C) \1/
  }' doc/tar.texi
2026-01-23 17:38:38 -08:00
Paul Eggert
505cf47a0a Fix commit typo when bringing back placeholders
Problem reported by Pavel Raiskup in:
https://lists.gnu.org/r/bug-tar/2025-11/msg00028.html
* src/extract.c (contains_dot_dot): Bring back this function here,
from its former location in src/names.c.  Make it static since
it is used only in this compilation unit.
2025-11-27 11:21:49 -08:00
Paul Eggert
f83a120c58 Bring back placeholders
They can still be useful if -h is used.  See Pavel Cahyna in:
https://lists.gnu.org/r/bug-tar/2025-11/msg00026.html
while we’re at it bring them back if -P is used,
as they can still be useful there too.
* src/extract.c (HAVE_BIRTHTIME, BIRTHTIME_EQ):
Bring back these macros.
(struct delayed_link, struct string_list):
Bring back these structs.
(delayed_link_table, delayed_link_head, delayed_link_tail):
Bring back these static vars.
(dl_hash, dl_compare, find_direct_ancestor)
(find_delayed_link_source, create_placeholder_file)
(apply_delayed_link, apply_delayed_links):
Bring back these static functions.
(mark_metadata_set): Rename from mark_after_links.  All uses changed.
(extract_link, extract_symlink):
Create placeholders as before, except only if -P or -h are used.
(extract_finish): Deal with delayed links, as before.
2025-11-26 20:49:38 -08:00
Paul Eggert
2bbc58bf0b Support gnulib-style timestamps in checkpoint logs
* gnulib.modules: Add nstrftime-limited, time_rz.  Sort.
* src/checkpoint.c: Include <strftime.h>.
(format_checkpoint_string): Use nstrftime instead of strftime.
Also fix an obscure bug on platforms that lack tm_gmtoff+tm_zone by
calling tzalloc on those platforms; if it fails, fall back on gmtime.
Also, use fwrite instead of fprintf, since we typically know the
length already and this gives us a more-accurate byte count
in case there are partial writes.
2025-11-23 09:51:31 -08:00
Paul Eggert
85d99f18af build: update gnulib submodule to latest 2025-11-23 09:51:31 -08:00
Paul Eggert
db65c2dd68 Port to C23 qualifier-generic fns like strchr
* src/checkpoint.c (getarg):
* src/tar.c (expand_pax_option):
Const-qualify results of strchr etc. if args are const-qualified.
2025-11-23 09:51:31 -08:00
Paul Eggert
28556dddae build: update gnulib submodule to latest 2025-11-17 16:40:18 -08:00
Paul Eggert
cdc541ad52 Prefer countof to sizeof / sizeof
C2y plans to introduce a new countof operator that will be
convenient for GNU tar, so start using it now via Gnulib.
* gnulib.modules: Add stdcountof-h.
* lib/wordsplit.c, src/buffer.c, src/suffix.c, src/tar.c:
Include stdcountof.h, and prefer countof (X) to sizeof X / sizeof *X.
2025-11-15 15:50:05 -08:00
Paul Eggert
2e243986c7 Port new extraction test to FreeBSD 15
* tests/extrac31.at (extracting untrusted incremental):
Port to FreeBSD 15 wording.
2025-11-15 15:10:48 -08:00
Paul Eggert
db9ca8d754 Port to compilers where COMMON_INLINE is static
Problem found with clang 15.0 on CheriBSD.
* src/names.c (namelist_match, register_match):
Now plain static, not static COMMON_INLINE, since the later
could mean the declaration is ‘static static’ which is not allowed.
2025-11-15 15:10:48 -08:00
Paul Eggert
b53b39209e Pacify clang 14 -Wbitwise-conditional-parentheses
* src/common.h (add_printf):
* src/sparse.c (decode_num):
Parenthesize to pacify Apple clang version 14.0.0 (clang-1400.0.29.202).
2025-11-15 15:10:48 -08:00
Paul Eggert
8d8e441bb5 Skip sparse test on non-sparse file systems
* tests/sparse05.at (listing sparse files bigger than 2^33 B):
If there were problems generating BIGFILE remove it,
as it has likely exhausted the file system.
Problem found on Darwin 21.6 APFS.
2025-11-15 15:10:48 -08:00
Paul Eggert
453d903de9 Adjust to Gnulib strftime changes for macOS
Stop using the fprintftime module, as as with recent Gnulib changes
it breaks the build on macOS, and fixing this would drag in threading
libraries and macOS-specific libraries that are overkill for tar.
Instead, just use strftime; that’s good enough here and arguably
better in case someone attacks tar with a huge time format string.
* gnulib.modules: Remove fprintftime.
* src/checkpoint.c: Do not include fprintftime.
(format_checkpoint_string): Always output some useful info (a decimal
seconds count), even if localtime fails. Do not output more than
256 bytes of time info, as that’s likely a DoS attack.  Stick with
plain strftime, as fprintftime’s extra features are overkill here.
2025-11-15 15:10:48 -08:00
Paul Eggert
0521528cdf Port intmax macro to strict C11
Needed for Apple clang version 14.0.0 (clang-1400.0.29.202).
* src/common.h (intmax): Define macro only if _Generic works, and
use _Generic in it rather that using EXPR_SIGNED.  This is needed
to make the first argument of verify_expr an integer constant
expression, which is required for strict C11.  Although GCC is
smart enough to treat (1 ? 0 : V) as an integer constant
expression even if V is an integer variable, C11 does not require
support for this sort of thing.
2025-11-15 15:10:48 -08:00
Paul Eggert
4e548d150c Port new tests to Solaris 10 strerror
* tests/extrac31.at: Adjust to Solaris 10 diagnostics.
2025-11-15 15:10:48 -08:00
Paul Eggert
50b559c3d7 Do not create empty placeholder files
* src/extract.c (HAVE_BIRTHTIME, BIRTHTIME_EQ, struct delayed_link)
(delayed_link_table, delayed_link_head delayed_link_tail)
(struct string_list, dl_hash, dl_compare, find_direct_ancestor)
(find_delayed_link_source, create_placeholder_file, apply_delayed_link)
(apply_delayed_links): Remove.  All uses removed.
(struct delayed_set_stat): New member metadata_set,
replacing after_links.  All uses changed.
(apply_nonancestor_delayed_set_stat): Arg METADATA_SET replaces
the old AFTER_LINKS.  All callers changed.
(extract_archive): Do not worry about "..", since openat2
now does that for us.
* src/names.c (first_dot_dot): Remove.  All uses removed.
2025-11-15 15:10:48 -08:00
Paul Eggert
75b03fdff4 Use openat2 to jailify the extraction directory
This addresses CVE-2025-45582.
* gnulib.modules: Add openat2.
* src/misc.c (open_subdir): New static function.
(fdbase_opendir): Use it.
* src/tar.c (open_searchdir_how): New var, replacing and
augmenting open_searchdir_flags.  All uses changed.
* tests/extrac31.at: New file.
* tests/Makefile (TESTSUITE_AT), tests/testuite.at: Add it.
2025-11-15 15:10:48 -08:00
Paul Eggert
aec5d77437 Omit trailing white space and empty lines 2025-11-15 15:10:48 -08:00
Paul Eggert
8ba9e244e8 Standardize on “working directory” 2025-11-15 15:10:48 -08:00
Paul Eggert
e1445cfdf0 Use fewer flags when opening directories
This doesn’t change behavior; it is a refactoring for
compatibility with a future patch that will use Linux’s
openat2 syscall, which is pickier about flags.
* src/tar.c (decode_options): When searching directories,
do not use O_NOCTTY, O_NONBLOCK, and O_NOATIME.
openat2 rejects all three flags if O_PATH is used.
The first two flags are definitely irrelevant for directories,
and O_NOATIME probably doesn’t matter either.
2025-11-15 15:10:48 -08:00
Paul Eggert
915a8077af Improve performance of relative opendir
* src/misc.c (fdbase_opendir): When the new directory is a
subdirectory of the old one, open relative to the old one rather
than relative all the way back to chdir_fd, and if that open fails
for a non-EMFILE reason, keep rather than discard the old directory.
2025-11-15 15:10:48 -08:00
Paul Eggert
cdb586803b Work around Oracle Developer Studio compiler bug
* src/create.c (dump_file0): Reword.
2025-11-15 15:10:48 -08:00
Paul Eggert
bdd773d028 Cache parent directories
Although this might help (or hurt) performance, the main
motivation is to make it easier in future commits
to prevent tarballs from escaping the extraction directory.
* src/common.h: (BADFD): New constant.
(struct fdbase): New type.
* src/create.c (dump_file0): Use parent->fd instead of caching
it into a local, as the latter approach is now awkward.
* src/extract.c (extract_link): Don’t save errno unless needed.
* src/misc.c (safer_rmdir): New arg F.  All callers changed.
(maybe_backup_file): Construct full after_backup_name, now
that find_backup_file_name no longer does that for us.
(chdir_fd): Now static not extern, as other modules now use fdbase.
(fdbase_cache): New static var.
(fdbase_clear): New function.  Call it whenever removing
or renaming directories or symlinks to directories.
(fdbase_opendir): New static function.
(fdbase, fdbase1): New functions.  Call them whenever the
code formerly passed chdir_fd to a syscall.
2025-11-15 15:10:48 -08:00
Paul Eggert
382a47f2fd Prefer issymlinkat
* gnulib.modules: Add issymlinkat, already an indirect dependency.
* src/extract.c: Include issymlink.h.
(is_directory_link, open_output_file):
Prefer issymlinkat to doing it by hand.
2025-11-15 15:10:48 -08:00
Paul Eggert
a109947a78 Make xclose static
* src/buffer.c (xclose): Move from here ...
* src/system.c: ... to here, and make it static.
2025-11-15 15:10:48 -08:00
Paul Eggert
8fca2d35e8 Prefer O_PATH to O_SEARCH on Linux kernels
* src/tar.c (decode_options): Prefer O_PATH to an O_SEARCH that is
actually O_RDONLY.
2025-11-15 15:10:48 -08:00
Paul Eggert
238250f19e Prefer streq/memeq when they will do
Gnulib’s new streq and memeq functions make code a bit more
readable and, we hope, a bit more reliable and easy to maintain.
* gnulib.modules: Add stringeq.
* lib/wordsplit.c (wordsplit_find_env):
* src/buffer.c (check_compressed_archive, check_tty)
(_open_archive, new_volume, try_new_volume)
(drop_volume_label_suffix):
* src/checkpoint.c (checkpoint_compile_action):
* src/compare.c (process_rawdata, diff_symlink):
* src/create.c (cachedir_file_p):
* src/delete.c (delete_archive_members):
* src/exclist.c (hg_addfn, get_vcs_ignore_file):
* src/extract.c (ds_compare, remove_delayed_set_stat)
(fixup_delayed_set_stat, apply_nonancestor_delayed_set_stat)
(extract_link):
* src/incremen.c (nfs_file_stat, compare_directory_canonical_names)
(procdir):
* src/list.c (read_header, decode_header):
* src/misc.c (replace_prefix):
* src/names.c (uname_to_uid, gname_to_gid, read_next_name)
(name_compare):
* src/sparse.c (check_data_region):
* src/suffix.c (find_compression_suffix):
* src/system.c (sys_detect_dev_null_output)
(sys_child_open_for_compress, sys_child_open_for_uncompress):
* src/tar.c (set_archive_format, tar_set_quoting_style)
(optloc_eq, set_use_compress_program_option, decode_signal)
(report_textual_dates, decode_options):
* src/update.c (update_archive):
* src/warning.c (set_warning_option):
* src/xattrs.c (xattrs_xattrs_set):
* src/xheader.c (xheader_keyword_override_p)
(xheader_set_keyword_equal, locate_handler)
(xheader_protected_keyword_p):
Prefer memeq/streq to memcmp/strcmp when either will do.
2025-11-15 15:10:48 -08:00
Paul Eggert
7c241126f1 Refactor to avoid duplication in "./" scanning
* src/exclist.c (excluded_name):
* src/misc.c (normalize_filename_x, must_be_dot_or_slash)
(chdir_arg):
Use dotslash or dotslashlen instead of doing things by hand.
* src/misc.c (slashlen, dotslashlen): New functions.
(safer_rmdir): Do not worry about unlinkat with AT_REMOVEDIR
succeeding on ".", as POSIX prohibits it, and it does not succeed
on any known platform. This simplifies the file name test.
Continue to worry about "/" though, as POSIX does allow
it to be removed.
2025-11-15 15:10:48 -08:00
Paul Eggert
56fb4a96ca chdir_id refactoring
This prepares for future changes that need directory IDs.
* src/common.h (struct chdir_id): New struct.
* src/extract.c (extract_dir): Use chdir_id to avoid duplicate stats.
* src/misc.c (struct wd): New member ID.
(grow_wd): New function, extracted from chdir_arg and that
also initializes id.err.
(chdir_arg): Use it.  Initialize id.err.
(chdir_id): New function.
2025-11-15 15:10:48 -08:00
Paul Eggert
83cad5835f Remove unreachable assignment to mtime.tv_nsec
Caught by Oracle Developer Studio 12.6
* src/incremen.c (read_incr_db_01): Remove unreachable code.
2025-11-15 15:10:48 -08:00
Paul Eggert
58b471f14a Omit duplicate declaration of ‘usage’ 2025-11-15 15:10:48 -08:00
Paul Eggert
f8b087a9f8 * README-hacking: Add testing note. 2025-11-15 15:10:48 -08:00
Paul Eggert
109edc9edb Fix test to match paxutils quoting change
* tests/incr08.at (filename normalization):
Adjust test to match quoting change in paxutils.
2025-11-15 15:10:48 -08:00
Paul Eggert
08e42808b6 Use Gnulib gendocs instead of our own
I ported our fix into Gnulib so there’s no longer a need
for a separate copy.
* doc/Makefile.am (GENDOCS): Now in ../build-aux, not here.
* doc/gendocs.sh, doc/gendocs_template: Remove.
* gnulib.modules: Add gendocs.
2025-11-15 15:10:48 -08:00
Paul Eggert
0b7d124e36 maint: sync bootstrap, fdl.texi from Gnulib 2025-11-15 15:10:48 -08:00
Paul Eggert
ca6af3a7f5 build: update gnulib and paxutils submodules to latest 2025-11-15 15:10:48 -08:00
Matteo Croce
92f040151c fix build error when compiling with --without-xattrs
* src/extract.c (set_xattr):
* src/xattrs.c (xattrs_xattrs_add, xattrs_xattrs_get, xattrs_xattrs_set):
Add MAYBE_UNUSED.
Copyright-paperwork-exempt: yes
2025-11-12 17:21:42 -08:00
David Leadbeater
5def5cb369 Quote arguments in diagnostic messages.
Copyright-paperwork-exempt: yes
2025-11-12 13:11:00 +02:00
Sergey Poznyakoff
f501cf8c9a Version 1.35.90 2025-10-19 09:39:14 +03:00
Collin Funk
2737e1aec0 maint: Update library names used by Gnulib.
* src/Makefile.am (tar_LDADD):
* tests/Makefile.am (LDADD): Update library names according to Gnulib.

Copyright-paperwork-exempt: yes
2025-08-19 21:12:59 -07:00
Paul Eggert
ca02de4050 Avoid overrun when converting ns-resolution timestamps to text
Caught by gcc -fsanitize=address.
Inspired by Matthias Andree’s bug report in:
https://lists.gnu.org/r/bug-tar/2025-08/msg00019.html
though I found this bug via a simple "make check"
with sanitization enabled.
* src/common.h (TIMESPEC_STRSIZE_BOUND):
Make room for leading '-', needed in addition to the '-' room
supplied by SYSINT_BUFSIZE due to the way code_timespec works.
2025-08-18 17:14:49 -07:00
Paul Eggert
ea7cfcba77 Avoid hash_meta_directory int overflow
* src/incremen.c (hash_directory_meta):
Avoid possibility of signed integer overflow.
2025-08-14 10:27:28 -07:00
Paul Eggert
bdc442bd5c Use Gnulib’s same-inode module
This is more portable to non-POSIX systems.
However, don’t bother trying to port to systems
where st_ino is not a scalar of type dev_t,
as these systems no longer seem to be active targets
and it’s not worth the maintenance hassle.
* gnulib.modules: Add same-inode, now that we use it
explicitly rather than indirectly.
* src/compare.c (diff_link):
* src/create.c (compare_links, restore_parent_fd):
* src/incremen.c (compare_directory_meta, procdir):
* src/extract.c (dl_compare, repair_delayed_set_stat)
(apply_nonancestor_delayed_set_stat, extract_link)
(apply_delayed_link):
* src/names.c (add_file_id):
* src/system.c (sys_file_is_archive, sys_detect_dev_null_output):
Include same-inode.h, and prefer its macros and functions
to doing things by hand.
* src/create.c (struct link):
* src/extract.c (struct delayed_set_stat, struct delayed_link):
* src/incremen.c (struct directory):
* src/names.c (struct file_id_list):
Rename members to st_dev and st_ino so that SAME_INODE and
PSAME_INODE can be used on the type.  All uses changed.
* src/system.c (sys_compare_links): Remove.
All uses replaced by psame_inode.
2025-08-14 10:27:28 -07:00
Collin Funk
5402831d62 manual: remove '.info' suffix in manual names passed to @xref
Texinfo 7.2 began warning about the '.info' suffix in the manual names
passed to @xref and similar commands.  They eventually plan to stop
stripping the '.info' suffix internally which will lead to broken links
in the manuals without this change.

* doc/tar.texi (files): Remove '.info' suffix from manual name.
2025-08-07 23:56:50 -07:00
Paul Eggert
4e742fc867 --no-overwrite-dir no overwrite even temporarily
Problem and fix reported by Pavel Cahyna in
https://lists.gnu.org/r/bug-tar/2025-01/msg00000.html
* src/extract.c (extract_dir): With --no-overwrite-dir,
skip the chmod if the directory already exists.
* tests/extrac23.at (--no-overwrite-dir on empty directory):
Move the part of the test that looks at a nonempty directory ...
* tests/extrac30.at: ... to this new file, because the test now
must be run as non-root.  Adjust the test to match the new behavior.
* tests/Makefile.am (TESTSUITE_AT), tests/testsuite.at: Add it.
2025-07-26 21:49:20 -07:00
Paul Eggert
076818f8d9 Use flexible array member in struct dumpdir
* src/incremen.c: Include flexmember.h.
(struct dumpdir): contents is now a flexible member, not a pointer.
This is more idiomatic and slightly more efficient.
(dumpdir_create0): Adjust to the new struct dumpdir layout.
2025-07-26 02:20:53 -07:00