1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-02-10 17:31:56 +02:00
Commit Graph

30821 Commits

Author SHA1 Message Date
Collin Funk
dac96ce3e3 timeout: use the more efficient posix_spawn to invoke the command
* NEWS: Mention the improvement. Consolidate the posix_spawn
improvements into one item.
* bootstrap.conf (gnulib_modules): Add posix_spawnattr_setsigmask.
* src/timeout.c: Include spawn.h.
(main): Setup signals using a posix_spawnattr_t object. Use posix_spawn
instead of fork and execvp.
2025-10-27 16:54:45 -07:00
Collin Funk
ffa2632dcd maint: prefer ckd_add for overflow checks
* src/cksum.c (cksum_slice8, crc32b_sum_stream): Use ckd_add to check
for overflow.
* src/cksum_avx2.c (cksum_avx2): Likewise.
* src/cksum_avx512.c (cksum_avx512): Likewise.
* src/cksum_pclmul.c (cksum_pclmul): Likewise.
* src/cksum_vmull.c (cksum_vmull): Likewise.
2025-10-27 16:52:16 -07:00
Pádraig Brady
8ba47d09a3 build: don't build chcon or runcon unless selinux is available
The build can be force enabled with --with-selinux and vice versa.

* build-aux/gen-lists-of-programs.sh: Move chcon and runcon
to the list of optional programs.
* configure.ac: Only enable chcon and runcon if selinux.h is available.
* NEWS: Mention the Build-related change.
Fixes https://github.com/coreutils/coreutils/issues/121
2025-10-27 16:57:39 +00:00
Collin Funk
2b3eb795c8 sort: use the more efficient posix_spawn to invoke --compress-program
* NEWS: Mention the improvement. Mention that 'sort' will continue
without compressing temporary files if the program specified by
--compress-program cannot be executed.
* doc/coreutils.texi (sort invocation): Document the behavior when the
program specified by --compress-program cannot be executed.
* src/sort.c: Include spawn.h.
(MAX_FORK_TRIES_COMPRESS, MAX_FORK_TRIES_DECOMPRESS): Remove definition.
(MAX_TRIES_COMPRESS, MAX_TRIES_DECOMPRESS): New definitions based on
MAX_FORK_TRIES_COMPRESS and MAX_FORK_TRIES_DECOMPRESS.
(async_safe_die): Remove function.
(posix_spawn_file_actions_move_fd): New function.
(pipe_fork): Remove function.
(pipe_child): New function based on pipe_fork. Return an error number
instead of a pid. Use posix_spawnp instead of calling fork and expecting
the caller to exec.
(maybe_create_temp): Call pipe_child instead of pipe_fork. Print a
warning to standard error if --compress-program cannot be executed and
the error is different than the previous call. Remove code for the child
process.
(open_temp): Remove code for the child process. Improve error message.
* tests/sort/sort-compress.sh: Add a test case for when the program
specified by --compress-program does not exist.
2025-10-25 12:59:08 -07:00
Collin Funk
a2a2f22efe maint: remove unnecessary ignore_value usage
* src/install.c: Remove ignore-value.h include.
(strip): Don't use ignore_value on posix_spawnattr_destroy since it
isn't declared with the warn_unused_result attribute. Pass the checked
pointer to posix_spawnattr_destroy instead of the variable it points to.
2025-10-23 14:40:39 -07:00
Bernhard Voelker
8b60d7a5aa install: enhance error diagnostic when running strip fails
* src/install.c (strip): Mention explicitly that the strip program
failed in the case the user specified a custom strip program name.
2025-10-23 22:37:16 +02:00
Collin Funk
2213542e40 split: cleanup after posix_spawn
* boostrap.conf (gnulib_modules): Add posix_spawn_file_actions_destroy.
* src/split.c (cleanup): Call posix_spawnattr_destroy and
posix_spawn_file_actions_destroy after a successful posix_spawn.
2025-10-23 12:42:01 -07:00
Collin Funk
ca8b928665 split: prefer posix_spawn to fork and execl
* NEWS: Mention the change.
* bootstrap.conf (gnulib_modules): Add posix_spawn,
posix_spawnattr_setsigdefault, posix_spawn_file_actions_addclose,
posix_spawn_file_actions_adddup2, and posix_spawn_file_actions_init.
* src/split.c: Include spawn.h.
(create): Use posix_spawn instead of fork and execl.
2025-10-23 11:24:06 -07:00
Pádraig Brady
1dabab7027 tests: date: test --resolution and %-N
* tests/date/resolution.sh: New test for --resolution and %-N.
* tests/local.mk: Reference the new test.
2025-10-23 17:40:13 +01:00
Pádraig Brady
14d24f7a53 tests: date: test --reference
* tests/date/reference.sh: Ensure the -r option is tested.
* tests/local.mk: Add the test.
2025-10-23 17:40:12 +01:00
Pádraig Brady
c5b147fabf pr: promptly diagnose write errors
* src/pr.c (print_page): Exit promptly for `yes | pr`.
(print_clump): Exit promptly for `pr < /dev/zero`.
* tests/misc/write-errors.sh: Enable test cases.
* NEWS: Mention the improvement.
2025-10-22 19:11:37 +01:00
Pádraig Brady
9415cf01c6 nl: promptly diagnose write errors
* NEWS: Mention the improvement.
* src/nl.c (process_file): Exit if error outputting line.
* tests/misc/write-errors.sh: Enable the test case.
2025-10-22 16:32:34 +01:00
Pádraig Brady
c12a2ecb53 fmt: promptly diagnose write errors
* NEWS: Mention the improvement.
* src/fmt.c (put_line): Exit if any error writing line.
(flush_paragraph): Exit if any error writing buffer.
* tests/misc/write-errors.sh: Enable the (flush_paragraph) test case,
and add another to check the put_line() case.
2025-10-22 16:18:06 +01:00
Pádraig Brady
5971f450b5 numfmt: promptly diagnose write errors
* src/numfmt.c (process line): Inspect the stdio error state when
outputting each line so that we don't have to check each output function
but do eventually exit upon write error, while also remaining buffered.
(main): Also check when outputting a header for the edge case
of very long headers.
* tests/misc/write-errors.sh: Enable the numfmt test case.
* NEWS: Mention the improvement, and reorganize all numfmt improvements.
2025-10-22 15:53:06 +01:00
Collin Funk
0c1334eb68 install: prefer posix_spawnp to fork and execlp
* NEWS: Mention the change.
* bootstrap.conf (gnulib_modules): Add posix_spawnattr_destroy,
posix_spawnattr_init, posix_spawnattr_setflags, and posix_spawnp.
* src/install.c (strip): Use posix_spawnp instead of fork and execlp.
2025-10-21 20:26:59 -07:00
Collin Funk
7c6c7095b9 maint: remove a redundant write after mcel_scan returns an error
* gl/lib/mbbuf.h (mbbuf_get_char): Don't set G.len to 1, since mcel_err
has already done it.
2025-10-20 15:14:16 -07:00
Pádraig Brady
38b824ac7e tests: numfmt: add non-utf8 multi-byte test
* tests/numfmt/mb-non-utf8.sh: Test GB18030 delimiter search.
* tests/local.mk: Reference the new test, and move
the existing numfmt.pl test from tests/misc to tests/numfmt.
2025-10-20 13:27:33 +01:00
Pádraig Brady
e58f9390f1 numfmt: optimize multi-byte --delimiter search
* src/numfmt.c (is_utf8_charset): A new function to efficiently
determine if running with a UTF-8 charset.
(mbsmbchr): A new function to efficiently search for
a (multi-byte) character in a multi-byte string.
(next-field): Use mbsmbchr() rather than mbstr() directly.
2025-10-20 13:13:25 +01:00
Pádraig Brady
09af58f4f9 numfmt: support multi-byte --delimiter
* bootstrap.conf: Depend on mbsstr() to robustly search for a
multi-byte delimiter character (string) within a multi-byte string.
* src/numfmt.c (main): Accept a valid multi-byte delimiter character.
(next_field): Adjust delimiter search from single byte
to multi-byte aware.  Use mbsstr to find the first match.
* tests/misc/numfmt.pl: Add test case.
* NEWS: Mention the improvement.
2025-10-20 13:13:24 +01:00
Pádraig Brady
e5d7764386 numfmt: use multi-byte aware suffix matching
* src/numfmt.c (process_suffixed_number): Use gnulib's
mbs_endswith() helper, which is more robust in non UTF-8 locales.
Also always output a devmsg if a suffix is specified.
2025-10-18 20:03:57 +01:00
Pádraig Brady
770078e315 numfmt: fix issues with multi-byte blanks
* src/numfmt.c (process_line): Restore byte overwritten with NUL,
as it may be part of a multi-byte blank.
(process_suffixed_number): Skip multi-byte blanks,
and correctly determine width with mbswidth().
(parse_format_string): Use c_isblank() to explicitly
indicate that's all the format spec supports.
* tests/misc/numfmt.pl: Add test cases.
* NEWS: Mention the bug fix.
2025-10-18 18:37:10 +01:00
Pádraig Brady
0f7babad38 numfmt: add --unit-separator
Output, accept, or disallow a string between the number and unit
as recommended in <https://physics.nist.gov/cuu/Units/checklist.html>
I.e. support outputting numbers of the form: "1234 M"

* src/numfmt.c (simple_strtod_human): Skip unit separator if present,
or disallow a unit separator if empty.
(double_to_human): Output unit separator if specified.
(main): Accept --unit-separator.
* tests/misc/numfmt.pl: Add test cases.
* doc/coreutils.texi: Describe the new option,
giving examples of interaction with --delimiter.
* NEWS: Mention the new feature.
* THANKS.in: Add Johannes Schauer Marin Rodrigues,
who provided a preliminary patch.
2025-10-17 19:16:26 +01:00
Pádraig Brady
006dfe4cd4 numfmt: support reading numbers with grouping characters
This does not validate grouping character placement,
and currently just ignores grouping characters.

* src/numfmt.c (simple_strtod_int): Skip grouping chars
that are part of a number.
* tests/misc/numfmt.pl: Add test cases.
* NEWS: Mention the improvement.
2025-10-17 17:26:30 +01:00
Pádraig Brady
8bc11f80a3 numfmt: support reading numbers with NBSP before unit
* src/numfmt.c (simple_strtod_human): Accept (multi-byte)
non-breaking space character between number and unit.
Note we restrict this to a single character between number
and unit, to allow less ambiguous parsing if multiple blanks
are used to delimit fields.
* tests/misc/numfmt.pl: Add test cases.
* doc/coreutils.texi (numfmt invocation): Fix stale description
--delimiter skipping whitespace.
* NEWS: Mention the improvement.
2025-10-17 17:26:25 +01:00
Nicolas Boichat
ab5fce879b tests: du/bigtime: try harder to find a suitable filesystem
* tests/du/bigtime.sh: At least on Linux, the ext4 filesystem
doesn't support such large timestamp, while tmpfs does.  Try a bit
harder to look for a filesystem with large timestamp support.
2025-10-16 18:28:52 +01:00
Collin Funk
1066d442c2 tests: date: check that the hour format of the current locale is used
* tests/date/date-locale-hour.sh: New file.
* tests/local.mk (all_tests): Add the new test.

Co-authored-by: Pádraig Brady <P@draigBrady.com>
2025-10-13 21:56:43 -07:00
Pádraig Brady
b4e02e0ef4 tests: fix false failure in recent memory limit test
* tests/basenc/bounded-memory.sh: Ensure we skip the test
upon failure to determine the memory lower bound.
Reported by Bruno Haible.
2025-10-13 13:22:38 +01:00
Pádraig Brady
b880b02c44 numfmt: fix buffer over-read (CWE-126)
* src/numfmt.c (simple_strtod_human): Check for NULL after pointer
adjustment to avoid Out-of-range pointer offset (CWE-823).
* NEWS: Mention the fix.
2025-10-11 12:37:56 +01:00
Pádraig Brady
dd3eab13ee tests: basenc: use less redundant naming
Rename to less redundant names, now that we use
a separate test directory per util.

* tests/basenc/basenc-bounded-memory.sh -> .../bounded-memory.sh
* tests/basenc/basenc-large.sh -> .../large-input.sh
* tests/local.mk: Reference new names.
2025-10-11 11:28:22 +01:00
Pádraig Brady
86234ebffa tests: fix memory limit determination in new test
* tests/basenc/basenc-bounded-memory.sh: The passed command
needs to succeed for memory limit determination to work.
2025-10-11 11:27:47 +01:00
Collin Funk
f88f0e5d44 tests: basenc: add a test for bounded memory operation
* tests/basenc/basenc-bounded-memory.sh: New file.
* tests/local.mk (all_tests): Add the test.
2025-10-11 01:33:15 -07:00
Sylvestre Ledru
ae0fcbba97 tests: ln -f: ensure existing link replaced
Identified here:
<https://github.com/uutils/coreutils/issues/8830>

* tests/ln/misc.sh: Add the check.
2025-10-10 18:19:47 +01:00
Pádraig Brady
51f27a15b0 tests: cksum: add a test case for robust file name parsing
* tests/cksum/cksum-c.sh: Add a test case where the file name
contains tagged format delimiter characters.
2025-10-07 15:58:36 +01:00
Pádraig Brady
ac91433916 maint: cksum: document a base64/hex parsing ambiguity with untagged
* src/digest.c (split_3): Mention the ambiguity in misinterpreting
base64 characters as hex is not a practical consideration.
Also add an example of both tagged formats which makes it
easier to interpret the parsing logic.
2025-10-07 15:58:36 +01:00
Pádraig Brady
4639257610 cksum: fix --check with untagged base64 format with tag matches
* src/digest.c (split_3): Fallback to untagged matching in the
case where -a is specified and we have matched a TAG in
the possibly base64 data.  This might happen in 1 in every 64K files.
Note we remove the modification of string S (and redundant streq) in
the tag matching, as that was not needed since v8.32-223-g217cd278e.
* tests/cksum/cksum-c.sh: Add a test case.
* NEWS: Mention the bug fix.
2025-10-07 15:58:36 +01:00
Pádraig Brady
e661c7a525 cksum: fix length validation with SHA2- tagged format
* src/digest.c (sha2_sum_stream): Change from unreachable()
to affirm() so that we have defined behavior unless
we configure with --disable-assert.
(sha3_sum_stream): Likewise.
(split_3): Validate SHA2-lengths before passing on.
* tests/cksum/cksum-c.sh: Add a test case.
* NEWS: Mention the bug fix.
2025-10-07 15:58:36 +01:00
Pádraig Brady
cd2a8edd84 cksum: fix --check with --algorithm=sha2
* src/digest.c (split_3): Look up the provided tag with -a sha2
because there is not a 1:1 mapping between them.
* tests/cksum/cksum-c.sh: Add a test case.
* NEWS: Mention the bug fix.
2025-10-07 15:58:34 +01:00
Paul Eggert
311c04c059 rm: remove redundant mark_ancestor_dirs call
* src/remove.c (rm_fts): Remove unnecessary call.  Since this code
is executed only when not recursive, there are no ancestors to mark.
2025-10-06 13:37:22 -07:00
Paul Eggert
bae32db8fe rm: make ‘rm -d DIR’ more like ‘rmdir DIR’
* src/remove.c (rm_fts): When not recursive,
arrange for ‘rm -d DIR’ to behave more like ‘rmdir DIR’.
This works better for Ceph snapshot directories.
Problem reported by Yannick Le Pennec (bug#78245).
2025-10-06 13:37:21 -07:00
Collin Funk
ce8c22d25f cksum: allow -a {blake2b,sha2,sha3} --check to work on base64
* NEWS: Mention the bug.
* src/digest.c (split_3): Check that the base64 digest matches the
length supported by the algorithm.
(digest_check): Check that the read digest matches the base64 length of
the algorithm's digest. The previous condition would not work for
'cksum -a blake2b -l 8 ...'.
* tests/cksum/cksum-base64-untagged.sh: New file.
* tests/local.mk (all_tests): Add the new test.
2025-10-05 15:38:27 -07:00
Paul Eggert
ebfd80083b maint: omit trailing white space in config.h
* configure.ac (FORTIFY_SOURCE): Don’t indent a line
where the indentation can cause trailing white space in config.h.
Problem reported by Grisha Levit (Bug#79567).
2025-10-03 17:06:00 -07:00
Collin Funk
dba5cdc24e maint: remove IRIX support
* src/ptx.c (main) [HAVE_SETCHRCLASS]: Remove call to setchrclass.
* src/stty.c (VREPRINT) [!VREPRINT && VRPRNT]: Remove definition.
2025-10-03 14:52:30 -07:00
Pádraig Brady
1b12425f67 tests: factor: add suggested large prime tests
* tests/factor/create-test.sh: Add 2 new large primes from:
https://github.com/coreutils/coreutils/issues/65
* tests/local.mk: Reference the 2 new generated tests.
2025-10-02 17:22:28 +01:00
Pádraig Brady
75e3888bd3 unexpand: fix heap buffer overflow with --tabs=[+/]NUM
This avoids CWE-122: Heap-based Buffer Overflow
where we could write blank characters beyond
the allocated heap buffer.

* src/expand-common.c (set_max_column_width): Refactor function from ...
(add_tab_stop): ... here.
(set_extend_size): Call new function.
(set_increment_size): Likewise.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/79555
2025-10-02 15:26:02 +01:00
Pádraig Brady
58ea3574e6 doc: man: consistently format -X[OPTIONAL] form
This is significant for the date, od, and pr commands
which have options of the form -X[OPTIONAL], which change like:

  diff -r man.orig/date.1 man/date.1
  < \fB\-I[FMT]\fR, \fB\-\-iso\-8601\fR[=\fI\,FMT\/\fR]
  > \fB\-I\fR[\fI\,FMT\/\fR], \fB\-\-iso\-8601\fR[=\fI\,FMT\/\fR]

  diff -r man.orig/od.1 man/od.1
  < \fB\-w[BYTES]\fR, \fB\-\-width\fR[=\fI\,BYTES\/\fR]
  > \fB\-w\fR[\fI\,BYTES\/\fR], \fB\-\-width\fR[=\fI\,BYTES\/\fR]

* man/help2man (convert_options): Support options of the form
-X[PARAM], so that we now consistently format them (in italics).
2025-10-02 10:14:16 +01:00
Pádraig Brady
1cac40b637 doc: man: consistently italicize --option parameters
This changes a few pages, but the changes in tail.1
concisely illustrate the resulting man page changes:

  $ diff -r man.orig/tail.1 man/tail.1
  < \fB\-c\fR, \fB\-\-bytes\fR=\fI\,[\/\fR+]NUM
  > \fB\-c\fR, \fB\-\-bytes\fR=\fI\,[+]NUM\/\fR

  < \fB\-f\fR, \fB\-\-follow[=\fR{name|descriptor}]
  > \fB\-f\fR, \fB\-\-follow\fR[=\fI\,{name|descriptor}\/\fR]

  < \fB\-n\fR, \fB\-\-lines\fR=\fI\,[\/\fR+]NUM
  > \fB\-n\fR, \fB\-\-lines\fR=\fI\,[+]NUM\/\fR

* man/help2man: Relax the option match so more --option
variations are supported, and passed through to convert_option().
Specifically more variations after '=' are now supported.
Also split and document the regular expression.
Reported at https://github.com/coreutils/coreutils/issues/84
2025-10-02 10:13:53 +01:00
Collin Funk
7d55fd0aa3 maint: prefer unreachable () to NOTREACHED comment
* src/tsort.c (search_item): Use unreachable () instead of NOTREACHED.
2025-10-01 23:44:18 -07:00
Collin Funk
16a6736389 fold: move multi-byte character reading to a module
* gl/modules/mbbuf: New file.
* gl/lib/mbbuf.c: Likewise.
* gl/lib/mbbuf.h: Likewise.
* gl/local.mk (EXTRA_DIST): Add the new files.
* bootstrap.conf (gnulib_modules): Add mbbuf.
* src/fold.c: Include mbbuf.h.
(fold_file): Use the mbbuf functions instead of calling fread and
handling the input buffer ourselves.
* cfg.mk (exclude_file_name_regexp--sc_preprocessor_indentation)
(exclude_file_name_regexp--sc_GPL_version): Match gl/lib/mbbuf.c and
gl/lib/mbbuf.h.
2025-09-30 19:45:44 -07:00
Mathieu Bordere
67e9068c5f wc: add AVX512 function for line counting
* configure.ac: Add detection of AVX512 intrinsics for wc.
* src/local.mk: Build AVX512 wc libraries.
* src/wc.c: Add runtime detection of AVX512 intrinsics and call
appropriate function when detected.
* src/wc.h (wc_lines_avx512): Declare function.
* tests/wc/wc-cpu.sh: Add a test that disables AVX512 intrinsics.
* src/wc_avx512.c: New file containing the wc -l implementation using
AVX512. The logic and code is reused from the AVX2 implementation with
slight adaptations. Replaced __builtin_popcount by __builtin_popcountll
and the combination of _mm256_cmpeq_epi8 and _mm256_movemask_epi8 by a
single call to _mm512_cmpeq_epi8_mask.
* NEWS: Mention the improvement.
2025-09-30 14:09:37 +01:00
Pádraig Brady
c6afc8fa67 maint: update valgrind instructions
* README-valgrind: Adjust to current repo structure,
and give clearer step by step instructions.
2025-09-28 00:25:06 +01:00