Commit Graph

3322 Commits

Author SHA1 Message Date
Paul Eggert
39d315e8ea ptrdiff_t, not int
* src/delete.c (delete_archive_members): Use ptrdiff_t, not int,
to count memory blocks.
(write_recent_bytes): Simplify remainder calculation.
2024-08-04 01:41:43 -07:00
Paul Eggert
bf195d4ae4 ptrdiff_t, not ssize_t
* src/buffer.c (bufmap_reset, _flush_write):
Use ptrdiff_t, not ssize_t, to record pointer differences.
POSIX allows systems where size_t is 64 bits but ssize_t is only 32;
Ultrix used to do that, though no current systems do.
2024-08-04 01:41:43 -07:00
Paul Eggert
a9372cf08a Prefer stdckdint.h to intprops.h
Problem reported by Collin Funk in:
https://lists.gnu.org/r/bug-tar/2024-07/msg00000.html
though this patch is more general than Collin’s suggestion.
* src/compare.c (diff_multivol):
* src/delete.c (move_archive):
* src/sparse.c (oldgnu_add_sparse, pax_decode_header):
* src/system.c (mtioseek):
Prefer ckd_add and ckd_mul to the intprops.h equivalents,
since stdckdint.h is now standard.
2024-08-04 01:41:43 -07:00
Paul Eggert
be1aa32c6d Use ckd_add in page_aligned_alloc
* src/misc.c (page_aligned_alloc): Use ckd_add
instead of doing overflow checking by hand.
2024-08-04 01:41:43 -07:00
Paul Eggert
8a3fc52972 Simplify read_header overflow checking
* src/list.c (read_header): Use ckd_add instead of
doing overflow checking by hand.  Although the old code
was correct on all practical hosts, the new code is simpler
and works even on weird hosts where SIZE_MAX <= INT_MAX.
2024-08-04 01:41:43 -07:00
Paul Eggert
927d67855e Cleaner overflow checking in xheader_read
* src/xheader.c (xheader_read): Prefer ckd_add to
doing overflow checking by hand.
2024-08-04 01:41:43 -07:00
Paul Eggert
c6a5af16ba maint: use static_assert
* gnulib.modules: Add assert-h, for static_assert.
* src/common.h, src/list.c, src/misc.c:
Prefer static_assert to #if + #error.  This doesn’t fix any bugs; it’s
just that in general it’s better to avoid the preprocessor.
2024-08-04 01:41:43 -07:00
Paul Eggert
dcc90722ac Fix tests/ckmtime.c arithmetic
* tests/ckmtime.c (main): Don’t assume time_t is signed.
Avoid integer overflows (quite possible if time_t is 32 bit).
Do calculations precisely, without any rounding errors.
2024-08-04 01:41:43 -07:00
Paul Eggert
7557fdd4df Fix unlikely overflow in utf8_convert
* src/utf8.c (utf8_convert): Check for integer overflow.
2024-08-04 01:41:43 -07:00
Paul Eggert
91ee466c8a Fix unlikely overflow in transform.c
* src/transform.c (_single_transform_name_to_obstack):
Use xinmalloc to check for integer overflow.
2024-08-04 01:41:43 -07:00
Paul Eggert
7079fc369b Better overflow checking for blocking factor
* src/tar.c (parse_opt): Use ckd_add and ckd_mul instead of
less-obvious code that relies on implementation-defined
conversions.
2024-08-04 01:41:43 -07:00
Paul Eggert
b26e798a0f xsparse cleanup, including integer overflow
* scripts/xsparse.c: Include inttypes.h, for strtoimax.
Don’t include stdint.h, since inttypes.h includes it.
Sort include directives.
Make all extern functions and vars static, except for ‘main’.
(string_to_off): Use strtoimax instead of doing overflow
checking by hand, incorrectly (it relied on undefined behavior).
(string_to_size): New arg MAXSIZE.  All callers changed.
(get_var): Return bool not int.  Fix unlikely integer overflow.
Use strncmp instead of memcmp, to avoid unlikely pointer overflow.
(read_xheader, read_map, main): Avoid unlikely integer overflow.
Check for I/O errors more consistently.
(main): Prefer bool to int, and put vars near use.
2024-08-04 01:41:43 -07:00
Paul Eggert
f22b9fe3ce maint: fix some unlikely wordsplit overflows
* gnulib.modules: Add reallocarray.
* lib/wordsplit.c: Include stdckdint.h.
(ISDELIM, expvar, isglob, scan_word):
Defend against strchr (s, 0) always succeeding.
(alloc_space, wsplit_assign_vars):
Fix some unlikely integer overflows, partly by using reallocarray.
(alloc_space): Avoid quadratic worst-case behavior.
(isglob): Return bool, not int.  Accept size_t, not int.
(to_num): Remove; no longer used.
(xtonum): Clarify the code the bit.  Rely on portable
conversion to unsigned char rather than problematic pointer cast.
2024-08-04 01:41:42 -07:00
Paul Eggert
8f094605a8 maint: prefer C23 if available
* gnulib.modules: Add std-gnu23.
2024-07-29 00:41:34 -07:00
Paul Eggert
26d1e4ddbc Add some gnulib.modules
* gnulib.modules: Add errno, limits-h, safe-read, sys_stat.
Not sure about the relationship between gnulib.modules
and paxutils/gnulib.modules, but anyway tar itself uses
these so we should depend on them.  (Perhaps it would be
better if there was just one Gnulib module list for tar;
that would be less confusing.)
2024-07-29 00:41:34 -07:00
Paul Eggert
ec35690e91 build: update gnulib and paxutils submodules to latest 2024-07-29 00:41:34 -07:00
Paul Eggert
3fa1fd0751 Pacify gcc 14 -Wanalyzer-null-argument
* src/tar.c (optloc_eq): Add another ‘assume’.
2024-07-27 00:26:42 -07:00
Paul Eggert
fd33f25989 Pacify gcc 14 -Wanalyzer-infinite-loop
* gnulib.modules: Add stddef, for ‘unreachable’.
* src/compare.c (dumpdir_cmp): Tell GCC that the default case
is unreachable.  Make just one pass through the string,
instead of two passes (one via strcmp, another via strlen).
2024-07-27 00:26:42 -07:00
Paul Eggert
45a86d45b2 maint: make a few funcs and vars static
* src/buffer.c (last_stat_time, write_fatal_details):
* src/tar.c (name_more_files):
* src/xattrs.c (xheader_xattr_add):
Now static.
2024-07-26 23:44:03 -07:00
Paul Eggert
afd073399a maint: remove GLOBAL as per GCC 14
* src/common.h (GLOBAL): Remove this macro, and all its uses.
It collides with GCC 14 and -Wmissing-variable-declarations.
Change all uses of GLOBAL to use extern instead,
and declare the variables in their respective .c files.
Move .c file’s extern declarations here, so that they
appear only once and are checked against definitions.
* src/names.c (unconsumed_option_tail): Now static.
2024-07-26 23:44:03 -07:00
Paul Eggert
9f1c32c18b Modernize use of Gnulib, paxutils
* configure.ac: Omit stuff no longer needed now that Gnulib or
paxlib does it, or the code no longer needs the configure-time checks.
Do not use AC_SYS_LARGEFILE (Gnulib largefile does this) or check
for fcntl.h, memory.h, net/errno.h, sgtty.h, string.h,
sys/param.h, sys/device.h, sys/gentape.h, sys/inet.h,
sys/io/trioctl.h, sys/time.h, sys/tprintf.h, sys/tape.h, unistd.h,
locale.h, netdb.h; these are all now standard, or old ways of getting
at magtapes are no longer needed and we now have only sys/mtio.h.
Do not check for lstat, readlink, symlink, and check only for
waitpid’s existence rather than attempting to replace it.
Do not check for decls of getgrgid, getpwuid, or time.
Check just once for iconv.h.
* gnulib.modules: Add largefile.
* lib/.gitignore, lib/Makefile.am (noinst_HEADERS, libtar_a_SOURCES):
Remove system-ioctl.h, which is no longer in paxlib.
All includes now changed to just check HAVE_SYS_MTIO_H directly.
* lib/wordsplit.c (wordsplit_c_escape_tab, wordsplit_errstr)
(wordsplit_nerrs):
Now static or an enum, and without any leading "_" in the name.
* src/buffer.c (record_start, record_end, current_block, records_read):
* src/delete.c (records_skipped): Add extern decl to pacify GCC.
* src/compare.c, src/create.c, src/extract.c: Omit uses of
HAVE_READLINK and HAVE_SYMLINK since we now let Gnulib deal with
platforms lacking readlinkat and symlinkat.
* src/system.c: Use "#if !HAVE_WAITPID" instead of "#if MSDOS".
2024-07-26 21:56:20 -07:00
Paul Eggert
4e0deb7416 build: update gnulib and paxutils submodules to latest 2024-07-26 21:56:20 -07:00
Paul Eggert
3d2c735b7c maint: higher-precision checkpoint timestamps
* src/checkpoint.c (format_checkpoint_string):
Use current_timespec to get nanosecond resolution.
This also frees us from the necessity of including <sys/time.h>
to use gettimeofday, which is removed in POSIX.1-2024.
2024-07-24 10:04:16 -07:00
Paul Eggert
bd066ac0a5 build: update gnulib and paxutils submodules to latest 2024-07-24 10:04:16 -07:00
Paul Eggert
b96cabb1ea Sync bootstrap from Gnulib 2024-07-24 10:04:16 -07:00
Paul Eggert
42d1143dd5 Sync bootstrap from Gnulib 2024-07-15 14:59:33 -07:00
Paul Eggert
2b9e2cc947 maint: adjust to Gnulib -Wsystem-headers change
* configure.ac: Do not suppress -Wsystem-headers, as
Gnulib no longer enables it.
2024-07-15 14:59:33 -07:00
Paul Eggert
1752231f9e build: update gnulib submodule to latest 2024-07-15 14:59:33 -07:00
Sergey Poznyakoff
5f2cda027d Various formatting fixes 2024-06-07 00:05:00 +03:00
Sergey Poznyakoff
1e6ce98e3a Fix spurious diagnostic during extraction of . with --keep-newer-files
Bug reported in https://savannah.gnu.org/bugs/?65838.

Bug introduced by 79d1ac38c1.

* src/extract.c (make_directories): Restore second argument.  This
reverts the change made in 79d1ac38c1.
(maybe_recoverable, rename_directory): Update calls to make_directories.
* tests/extrac27.at: New file.
* tests/Makefile.am: Add new test.
* tests/testsuite.at: Likewise.
2024-06-05 18:19:10 +03:00
Paul Eggert
883f2e6dca tar: fix current_block confusion
Problem reported by Robert Morris in:
https://lists.gnu.org/r/bug-tar/2024-03/msg00001.html
* src/delete.c (flush_file): Simply return at EOF,
so that current_block continues to point to end of input.
2024-03-03 13:28:23 -08:00
Paul Eggert
628c49250a tar: fix unlikely overflow
* src/delete.c (flush_file): Fix arithmetic overflow if
TYPE_MAXIMUM (off_t) - BLOCKSIZE < current_stat_info.stat.st_size.
2024-03-03 13:28:23 -08:00
Paul Eggert
21318f3856 tar: improve diagnostic for truncated archive
* src/buffer.c (seek_archive): If EOF has been read, don’t attempt
to seek past it.  This replaces a bogus "rmtlseek not stopped at a
record boundary" message with a better "Unexpected EOF in archive"
when I run ‘tar tvf gtar13c.tar’ using the gtar13.tar file here:
https://lists.gnu.org/r/bug-tar/2024-03/msg00001.html
2024-03-03 13:28:23 -08:00
Sergey Poznyakoff
fac2b4c11a Avoid gcc 13 "unused parameter" warnings 2024-01-16 14:28:19 +02:00
Sergey Poznyakoff
6ba24c31c6 Recognize suffixes .z (gzip) and .tzo (lzop) 2024-01-15 22:52:27 +02:00
Sergey Poznyakoff
7b65ae35ab Fix description of the CACHEDIR.TAG file. 2024-01-15 22:30:22 +02:00
Sergey Poznyakoff
f622c07108 Fix --exclude-ignore option.
This fixes https://savannah.gnu.org/bugs/?64387.

* src/exclist.c (info_attach_exclist): Always use file->flags.
(exclude_vcs_ignores): Pass flags from struct vcs_ignore_file
to excfile_add.

* tests/exclude19.at: New test.
* tests/exclude20.at: New test.
* tests/Makefile.am: Add new tests.
* tests/testsuite.at: Add new tests.
2024-01-15 21:24:34 +02:00
Sergey Poznyakoff
d763055edd Fix missing space in the manual 2024-01-15 20:21:26 +02:00
Sergey Poznyakoff
b4d1fa77b6 When given -c -a, issue a warning if no compressor is associated with the suffix.
* src/suffix.c (find_compression_suffix): Always return stripped
archive name length in the last argument.  Return 0 if there is no
suffix.
(find_compression_program): Remove.
(set_compression_program_by_suffix): Take third argument, controlling
whether to issue a warning if no suitable compression program is found
for the suffix.
* src/common.h (set_compression_program_by_suffix): Change prototype.
* src/buffer.c, src/tar.c: All uses of set_compression_program_by_suffix
changed.
2024-01-15 00:00:02 +02:00
Paul Eggert
66eaa2f821 Port EOF detection test to macOS
* tests/delete06.at: Don’t assume the diagnostic is
“Value too large for defined data type”, as strerror
uses a different wording on macOS 12.6.
2024-01-01 19:12:10 -08:00
Paul Eggert
24a2fcfd83 Skip test on macOS 12.6
* tests/xform04.at: Skip test on macOS 12.6, which is behind the times
and doesn’t think that ⱥ (U+2C65 LATIN SMALL LETTER A WITH STROKE) is
printable.
2024-01-01 19:12:10 -08:00
Paul Eggert
835b0c7dee Port --numeric-owner basic tests to macOS
* tests/numeric.at: If chown fails, skip the test.
This is needed on macOS 12.6 if the user has group
ID 4294967295 (nogroup), which chown rejects.
2024-01-01 19:12:10 -08:00
Paul Eggert
c6f0ad5117 Update copyright years
UPDATE_COPYRIGHT_USE_INTERVALS=1 \
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]*--\(2024 Free Software Foundation, Inc.\)/Copyright (C) \1/
  }' doc/tar.texi
2024-01-01 19:08:46 -08:00
Paul Eggert
f0098df0b3 doc: fix date in example
* doc/tar.texi: Fix copyright date in example.
2024-01-01 19:08:46 -08:00
Paul Eggert
3a27df1d69 build: update gnulib submodule to latest 2024-01-01 19:08:46 -08:00
Paul Eggert
c1e277476c Support multi-byte --transform='...\L...' etc
Support upcasing and downcasing in multi-byte locales.
* gnulib.modules: Add c32rtomb, c32tolower, c32toupper,
mbrtoc32-regular.
* src/transform.c: Do not include ctype.h.  Include mcel.h.
(stk, stk_init): Move up.
(run_case_conv): Return void, not char *.  Append result to
stk directly; this avoids the need for a separate allocation.
All callers changed.  Do not assume a single-byte locale.
* tests/xform04.at: New test.
* tests/Makefile.am (TESTSUITE_AT):
* tests/testsuite.at: Add it.
2023-09-12 23:23:41 -05:00
Paul Eggert
783321ff1b Simplify wordsplit_string_unquote_copy
* lib/wordsplit.c (wordsplit_string_unquote_copy): Simplify.
2023-09-12 23:23:41 -05:00
Paul Eggert
01f986b921 Parse in a more locale-independent way
update submodules to latest
* gnulib.modules: Add c-ctype.
* lib/wordsplit.c, src/buffer.c, src/exclist.c, src/incremen.c:
* src/list.c, src/misc.c, src/names.c, src/sparse.c, src/tar.c:
* src/xheader.c:
Include c-ctype.h, and use its API rather than ctype.h’s.
This is more likely to work when oddball locales are used.
* src/transform.c: Include ctype.h, since this module still uses
tolower and toupper (this is probably wrong - should be multi-byte).
2023-09-12 23:23:41 -05:00
Paul Eggert
05fcfaafb6 Use single is_octal_digit function
* src/list.c (ISOCTAL): Remove.
(is_octal_digit): New static function.
All uses of ISOCTAL and ISODIGIT replaced with is_octal_digit.
2023-09-12 23:23:40 -05:00
Paul Eggert
e35fe3a77c maint: fix THANKS misspellings
* THANKS: Fix recently-introduced misspellings.
2023-09-11 09:32:18 -05:00