Commit Graph
5882 Commits
Author SHA1 Message Date
Collin Funk 89a7510051 head: fix two bugs when eliding bytes from a pipe
* src/head.c (elide_tail_bytes_pipe): Don't set REM to BUFSIZ when the
REMAINDER is zero. Don't assume the input is longer than the given
number of bytes.
* tests/head/head-elide-tail.pl ($HEAD_TAIL_PIPE_BYTECOUNT_THRESHOLD)
($MULTIPLE, $FRACTION): New variables.
(@Tests): Add a few test cases for the bugs.
* NEWS: Mention the bug fixes.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-BMLRFV62.
2026-11-16 15:47:15 -08:00
Collin Funk ecb3396381 tests: head: set READ_BUFSIZE to BUFSIZ as done in src/head.c
* src/getlimits.c (main): Print the value of BUFSIZ.
* tests/head/head-elide-tail.pl ($limits): Save the results of
getlimits.
($READ_BUFSIZE): Set it to the value of BUFSIZ.
2026-11-16 15:41:56 -08:00
Collin Funk 2b0f8f9d82 ln: fix -srf creating a symbolic link to itself
* src/ln.c (do_link): Don't set SOURCE to REL_SOURCE before the backup
checks.
* tests/ln/relative.sh: Add two test cases.
* NEWS: Mention the bug fix.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-ET9AU19B.
2026-11-16 15:38:34 -08:00
Collin Funk 2a27d71fc0 tests: make strace also inject openat2
* init.cfg (get_open_syscalls_): New function based on
get_stat_syscalls_.
* tests/chcon/traversal-missing.sh: Use it.
* tests/shred/chmod-race.sh: Use it.
* tests/shred/fifo.sh: Use it.
2026-11-16 15:36:09 -08:00
Sylvestre Ledru 1e50b1b0dd tests: stat: check %#a adds a single leading 0
* tests/stat/stat-fmt.sh: Check %#a with various precisions and
widths, including for a mode of 0.

https://github.com/uutils/coreutils/pull/16393

Link: https://github.com/coreutils/coreutils/pull/463
2026-11-15 16:17:39 +00:00
Sylvestre Ledru ebc6a4e7e6 tests: nl: check option values starting with a hyphen
* tests/nl/nl.sh: Ensure -s, --number-separator and -d accept
values starting with '-', and that -b, -h, -f and -n diagnose
such values as invalid values rather than options.

https://github.com/uutils/coreutils/pull/16376

Link: https://github.com/coreutils/coreutils/pull/468
2026-11-15 16:17:39 +00:00
Sylvestre Ledru a1751bc276 tests: expand: check the column is kept across files and buffers
* tests/expand/expand.pl (f4, f5): New tests, for a line that
continues into the next file.
(long-1, long-2): New tests, for a line longer than a read buffer.

https://github.com/uutils/coreutils/pull/16346

Link: https://github.com/coreutils/coreutils/pull/467
2026-11-15 16:17:39 +00:00
Sylvestre Ledru 30b06b0eeb tests: seq: check -w with scientific notation
* tests/seq/seq.pl (eq-wid-16): New test.

https://github.com/uutils/coreutils/pull/14180

Link: https://github.com/coreutils/coreutils/pull/466
2026-11-15 16:17:39 +00:00
Sylvestre Ledru 62b40c901d tests: join: check -o fields after the file operands
* tests/join/join.pl (o-after-files-1, o-after-files-2): New tests,
ensuring a separate -o field is only taken while a file operand
still follows it.

https://github.com/uutils/coreutils/pull/16378

Link: https://github.com/coreutils/coreutils/pull/465
2026-11-15 16:17:39 +00:00
Sylvestre Ledru d66f7dc609 tests: stat: check an empty --format or --printf
* tests/stat/stat-printf.pl (f-empty, f-empty2, f-empty-terse)
(p-empty, fs-empty): New tests, ensuring an empty format is used
rather than the default one.

https://github.com/uutils/coreutils/pull/16451

Link: https://github.com/coreutils/coreutils/pull/464
2026-11-15 16:17:39 +00:00
Sylvestre Ledru 2da43a03b6 tests: stat: check the 0 flag with a precision
* tests/stat/stat-fmt.sh: Ensure an integer conversion with a
precision ignores the 0 flag, as printf does.

https://github.com/uutils/coreutils/pull/16368

Link: https://github.com/coreutils/coreutils/pull/462
2026-11-15 16:17:39 +00:00
Sylvestre Ledru 8d32a0aadb tests: pr: check -m with a separator and a page width
* tests/pr/pr-tests.pl (merge-sep, merge-sep-w, merge-Sep-w)
(merge-sep-W): New tests, ensuring -s joins merged lines unpadded
unless a width is given, -S keeps the padding, and -W wins over -w.

https://github.com/uutils/coreutils/pull/16236

Link: https://github.com/coreutils/coreutils/pull/461
2026-11-15 16:17:39 +00:00
Sylvestre Ledru dc159f5fa0 tests: dircolors: check TERM filtering of the built-in database
* tests/misc/dircolors.pl (builtin-no-term, builtin-unknown-term)
(builtin-unknown-term-ls): New tests, ensuring the built-in database
is filtered by TERM and COLORTERM, like a user-supplied one.

https://github.com/uutils/coreutils/pull/14408

Link: https://github.com/coreutils/coreutils/pull/460
2026-11-15 15:59:16 +00:00
Sylvestre Ledru 994f0f0983 tests: fmt: add -t tests with a one-line paragraph
* tests/fmt/base.pl (tagged-1, tagged-2, tagged-3, tagged-4, tagged-5):
New tests, checking the indent of the continuation lines of a
one-line tagged paragraph, with and without a prefix.

https://github.com/uutils/coreutils/pull/15712

Link: https://github.com/coreutils/coreutils/pull/459
2026-11-15 15:59:16 +00:00
Ismail Ramzi 3b77964c3c pr: avoid a heap overflow with a very wide line number
With -n and truncated lines, add_line_number() added NUMBER_WIDTH to
INPUT_POSITION without checking for overflow.  A tab at the start of a
line followed by a line number width near INT_MAX would wrap
INPUT_POSITION negative, and with -e the next tab would then be
expanded by more than the tab width, writing past the end of CLUMP_BUFF.
E.g., printf '\t\t\n' | pr -t -e -W2147483647 -n:2147483643
wrote 12 bytes into an 8 byte buffer.

* src/pr.c (add_line_number): Use ckd_add when advancing INPUT_POSITION.
(init_parameters): Likewise when computing NUMBER_WIDTH,
which overflowed with -n:2147483647.
* tests/pr/options.sh: Add test cases.
* NEWS: Mention the bug fix.

Link: https://github.com/coreutils/coreutils/pull/458
2026-11-15 12:32:36 +00:00
Pádraig Brady 57d6cc458b cp,mv,install: fix infinite loop with --backup=t and unreadable dirs
* gnulib: Update to get the fix.
* tests/cp/backup-unreadable.sh: Add a new test case.
* tests/local.mk: Reference the new test.
* NEWS: Mention the bug fix.
2026-11-15 12:30:40 +00:00
Pádraig Brady a80621e6aa chmod: fix silent skipping when /proc is unavailable
You can get ENOTSUP due to the system not supporting chmod(symlink),
but you can also get ENOTSUP on any file type if the system needs
/proc to emulate AT_SYMLINK_NOFOLLOW and /proc is not available.

Before this fix we had the problematic "Silent skip" in these cases:

Build glibc    Runtime Linux    With /proc           Without /proc
=============  ============  ===================  ====================
≤ 2.31         Any           gnulib emulation     Racy fallback
2.32–2.38      Any           glibc emulation      Silent skip
≥ 2.39         < 6.6         glibc emulation      Silent skip
≥ 2.39         ≥ 6.6         Native fchmodat2     Native fchmodat2

After this change (and the preceding gnulib change), we have:

Build glibc    Runtime Linux    With /proc           Without /proc
=============  ============  ===================  ====================
≤ 2.38         Any           gnulib emulation     Racy fallback
≥ 2.39         < 6.6         glibc emulation      Diagnose ENOTSUP
≥ 2.39         ≥ 6.6         Native fchmodat2     Native fchmodat2

The above tables assume /proc is available at ./configure time.
Other cases like musl < 1.2.4 are not considered,
but there should at least be no silent ignoring of issues
once reported by the underlying libc.

* src/chmod.c (process_file): Check we're operating on a symlink
if we get ENOTSUP, and only ignore the error in that case.
* tests/chmod/symlink-enotsup.sh: Add a new test.
* tests/local.mk: Reference the new test.
* NEWS: Mention the bug fix.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-PSCKLNL1.
2026-11-14 20:26:42 +00:00
Pádraig Brady fa578f1da4 chmod: fix skipped items with -R --dereference --preserve-root
Fix skipped processing of items after a symlink to '/'.

* src/chmod.c (process_file): Only skip with directory
visited in pre-order.
* tests/chmod/symlinks.sh: Add a test case (skipped if root).
* NEWS: Mention the bug fix.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-HWDZFHEJ.
2026-11-14 18:57:55 +00:00
Collin FunkandPádraig Brady 94b24850da timeout: handle child processes that use PTRACE_TRACEME
* m4/jm-macros.m4 (coreutils_MACROS): Check for ptrace.
* src/timeout.c [HAVE_PTRACE && (__linux__ || __ANDROID__)]: Include
sys/ptrace.h.
(resume_command): New function.
(main): Call it if the monitored command has been stopped.
* tests/timeout/ptrace-traceme.sh: New file.
* tests/local.mk (all_tests): Add the new test case.
* NEWS: Mention the improvement.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-AKDIHN0Y.

Co-authored-by: Pádraig Brady <P@draigBrady.com>
2026-11-13 20:12:25 -08:00
Collin Funk 20e9ffd8c5 split: fix two bugs occurring with filters that exit early
* src/split.c (bytes_split): Don't lseek when the offset is already at
the correct position from reading. Don't add 1 to TO_WRITE.
* tests/split/filter.sh: Add two test cases.
* NEWS: Mention the bug fixes.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-D5DVHK7A.
2026-11-13 18:47:23 -08:00
Collin Funk 3f8a5b5470 df: don't open non-directory operands
* src/df.c (automount_stat_err): Use O_DIRECTORY when opening operands.
Fall back to stat if open fails with ENOTDIR.
* tests/df/open.sh: New file.
* tests/local.mk (all_tests): Add the new test case.
* NEWS: Mention the bug fix.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-Z5SPLRCM.
2026-11-13 18:27:05 -08:00
Joao Matos 394427e691 tests: csplit: add a test for the fix in the previous commit
* tests/csplit/guard-input.sh: New file.
* tests/local.mk (all_tests): Add the new test.
2026-11-12 22:42:06 -08:00
Pádraig Brady 6b7abe6572 tail: ensure bounded operation when appending to input
`tail -n2 in >> in` already operated in a bounded manner,
so this makes tailing from the start with `tail -n+2 in >> in`
bounded also, operating only on the original file contents
and not increasing the size of 'in' forever.

Note this bounded operation does not apply with -f.

* src/tail.c (remaining_input): A new helper to return
the limit of the original file when output is the same file.
(tail_bytes): Use the new limit from remaining_input().
(tail_lines): Likewise.
* tests/tail/append-to-input.sh: Adjust accordingly.
Note this test was failing on Alpine due to its
different buffering behavior.  We're now consistent
over all file sizes and buffering behaviour in this case.
* NEWS: Mention the improvement.
Test failure reported by Bruno Haible.
2026-11-10 21:04:45 +00:00
Pádraig Brady 110efa89e0 tests: od: fix false failure on macOS
* tests/od/od-j.sh: Read from /dev/zero again,
as macOS stops reading at OFF_T_MAX.
2026-11-10 20:30:37 +00:00
Pádraig Brady 8026b38e21 tests: env: fix false failure with sh linked to multi-call binary
* tests/env/env.sh: Avoid calling "sh" with a modified argv[0],
as e.g. with busybox providing sh, it will fail with "applet not found".
Reported by Bruno Haible.
2026-11-10 20:01:17 +00:00
Pádraig Brady c0146c7c60 tests: timeout: fix false failure with older bash
This was seen on Centos 7 at least with bash 4.2.46.

* tests/timeout/timeout.sh: Ensure the shell doesn't incorrectly
optimize itself away when there are traps in place.
Reported by Bruno Haible.
2026-11-10 17:57:23 +00:00
Pádraig Brady 9aeb2eeb0f tests: ls: fix false failure on non GLIBC systems
* tests/ls/line-separator.sh: Skip on systems that treat
U+2028 (LINE SEPARATOR), and U+2029 (PARAGRAPH SEPARATOR)
as printable.  Also since we're requiring our printf now,
use that to decouple the test from the particular shell-escape
quoting form used.
Reported by Bruno Haible.
2026-11-10 16:48:39 +00:00
Pádraig Brady f66f9b1146 cut,expand,fold,unexpand: fix handling of multi-byte with short reads
This change is performance neutral as tested with:
 $ yes $(yes eeeaae | head -n10K | paste -s -d,) | head -n10K > ll.in
 $ hyperfine src/cut{,.orig}' -f10 -w ll.in >/dev/null'

* gl/lib/mbbuf.h (mbbuf_fill): Repeat the mbbuf_topup(), i.e. the read()
if the previous run didn't read enough.  Note we add the explicit
common case short-circuit to avoid a 20% regression
for the test case above, with GCC 16.2 with -O3 -flto.
* tests/cut/mb-short-read.sh: A new test file.
* tests/local.mk: Reference the new test.
* NEWS: Mention the bug fix.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-JSCMJCN2.
2026-11-10 12:52:08 +00:00
Collin Funk 9704f18343 split: don't stop reading if a single filter stops accepting input
* src/split.c (of_t): Add the done member.
(lines_rr): Set the done member for the file if the filter has an
ignorable error. Don't attempt subsequent writes if the done member for
the file is set.
* tests/split/filter.sh: Add a test case.
* NEWS: Mention the bug fix.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-NO8YC6GS.
2026-11-09 16:09:49 -08:00
Sylvestre Ledru 40d9fe3e03 tests: ls: check a too long file name is reported as "cannot access"
* tests/ls/ls-misc.pl (name-too-long): New test.
https://github.com/uutils/coreutils/pull/15699

Link: https://github.com/coreutils/coreutils/pull/456
2026-11-09 00:24:53 +00:00
Sylvestre Ledru 64ea3f0553 tests: sort: check that a -t-like operand after -- is a file
* tests/sort/sort.pl (dash-dash-t): New test.
https://github.com/uutils/coreutils/pull/15823

Link: https://github.com/coreutils/coreutils/pull/450
2026-11-09 00:24:53 +00:00
Sylvestre Ledru 99ba5d505a tests: ls: check U+2028 and U+2029 are escaped or hidden
* tests/ls/line-separator.sh: New test.
* tests/local.mk (all_tests): Reference it.
https://github.com/uutils/coreutils/pull/16040

Link: https://github.com/coreutils/coreutils/pull/457
2026-11-09 00:24:52 +00:00
Sylvestre Ledru f5ded57fbd tests: tail: check output appended to the input stops at its end
* tests/tail/append-to-input.sh: New test.
* tests/local.mk (all_tests): Reference it.
https://github.com/uutils/coreutils/pull/15066

Link: https://github.com/coreutils/coreutils/pull/455
2026-11-09 00:19:10 +00:00
Sylvestre Ledru a041593749 tests: env: check a leading '=' in attached short option values
* tests/env/env.sh: Ensure -C=DIR, -vC=DIR, -S'-C=DIR ...' and -C=
change to a directory whose name starts with '=', that -a=NAME
sets argv[0] to '=NAME', and that -u=NAME and -vu=NAME are rejected.
https://github.com/uutils/coreutils/pull/15838

Link: https://github.com/coreutils/coreutils/pull/454
2026-11-09 00:13:38 +00:00
Sylvestre Ledru 981125e918 tests: od: check -t f4 and -t f8 use %g-style output
* tests/od/od-float.sh: Ensure 0.01, 1e-05 and 10 for -t f4 and
0.1 for -t f8 are printed with the shortest digits and two-digit
exponents.
https://github.com/uutils/coreutils/pull/15889

Link: https://github.com/coreutils/coreutils/pull/453
2026-11-09 00:13:38 +00:00
Sylvestre Ledru f7c67505cb tests: uniq: check diagnostics for invalid -f, -s and -w values
* tests/uniq/uniq.pl (147, 148, 149, 150, 151): New tests.
Ensure each option has its own message and that the value
is printed as given, including empty values and spaces.
https://github.com/uutils/coreutils/pull/15971

Link: https://github.com/coreutils/coreutils/pull/452
2026-11-09 00:13:34 +00:00
Sylvestre Ledru fc65b03e3f tests: od: check T, P and E suffixes after 0 or 0x in -N
* tests/od/od-N.sh: Ensure -N accepts octal and hex values
with T, P, E, TB, PB and EB suffixes.
https://github.com/uutils/coreutils/pull/15930

Link: https://github.com/coreutils/coreutils/pull/451
2026-11-08 23:30:10 +00:00
Collin Funk 20faee4d42 split: don't create more than N input files with -n l/N and short lines
* src/split.c (lines_chunk_split): Make sure CHUNK_NO does not exceed N.
* tests/split/l-chunk.sh: Add a test case without --elide-empty-files
and with it.
* NEWS: Mention the bug fix.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-ZDDBFXXM.
2026-11-08 12:36:23 -08:00
Collin Funk 79063df078 sort: don't share compressed temp files for the same input when merging
* src/sort.c (sortlines): Don't share compressed temporary files when
the same input is given multiple times.
* tests/sort/sort-compress-hang.sh: Add a test case that would
previously hang.
* NEWS: Mention the bug fix.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-MYSN7JAW.
2026-11-08 12:01:22 -08:00
Collin Funk 5b86ff66eb cp,mv,install: exit with status 1 when creating a hole fails
* src/copy-file-data.c (sparse_copy): Return -1 when create_hole fails.
* tests/cp/fail-create-hole.sh: New file.
* tests/local.mk (all_tests): Add the new test case.
* NEWS: Mention the bug fix.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-C18OTMQ2.
2026-11-08 11:00:49 -08:00
Pádraig Brady 4188d50eb4 tests: use more robust user and group matching
* tests/chgrp/from.sh: Force numeric lookup.
* tests/chmod/setgid.sh: Likewise.
* tests/chown/basic.sh: Likewise.
* tests/chown/preserve-root.sh: Likewise.
* tests/install/install-C-immutable.sh: Likewise.
* tests/install/install-C-root.sh: Likewise.
* tests/ls/nameless-uid.sh: Likewise.
* tests/misc/traversal-missing.sh: Likewise.
* tests/misc/user.sh: Likewise.
* tests/chown/deref.sh: Likewise.  Also avoid
name lookup which may fail if they contain spaces.
* tests/chown/verbose-dangling-symlink.sh: Likewise.
* tests/chgrp/verbose-dangling-symlink.sh: Likewise.
2026-11-08 15:29:10 +00:00
Sylvestre Ledru 572be620f0 tests: chown, chgrp: check "cannot access" vs "cannot dereference"
* tests/chown/cannot-access.sh: New test.  Ensure chown and chgrp
report "cannot access" for a missing operand, a trailing slash on a
non-directory and a missing file in a directory, and "cannot
dereference" only for a dangling symlink.
* tests/local.mk (all_tests): Reference the new test.
https://github.com/uutils/coreutils/pull/15868

Link: https://github.com/coreutils/coreutils/pull/449
2026-11-08 14:39:31 +00:00
Sylvestre Ledru 9e60b07a7c tests: date: test the '+' flag more thoroughly
* tests/date/date.pl: Check that '+' adds a sign only to year
conversions (%C, %y, %Y, %G, %F) whose width or value exceeds their
usual width, that it acts like '0' on other conversions, and that a
later '-', '_' or '0' flag cancels the sign.
https://github.com/uutils/coreutils/pull/16246

Link: https://github.com/coreutils/coreutils/pull/448
2026-11-08 14:17:59 +00:00
Sylvestre Ledru e0c24f5866 tests: chmod: ensure modes containing white space are rejected
* tests/chmod/mode-whitespace.sh: New test.  Check that chmod,
mkdir -m and install -m reject mode strings with leading or trailing
white space, or white space around a ',' separator.
* tests/local.mk (all_tests): Reference the new test.
https://github.com/uutils/coreutils/pull/16193

Link: https://github.com/coreutils/coreutils/pull/447
2026-11-08 14:06:17 +00:00
Pádraig Brady 27e21ce402 tests: avoid false failures on dash 0.5.13
dash 0.5.13 to 0.5.13.5 at least has a variable expansion bug:
https://bugzilla.redhat.com/2568651
This was seen on Fedora 44 and there is no upstream dash
release with a fix yet.

* init.cfg (bad_unicode): Avoid the dash issue, by comparing
the variable expansion and skipping upon mismatch.
* tests/du/block-size.sh: Add explicit checks for expansion
on values with high bit set.
* tests/paste/multi-byte.sh: Likewise.
2026-11-08 13:59:08 +00:00
Collin Funk 8121423eda pr: fix an infinite loop with a page of leading tabs and small columns
* src/pr.c: Continue processing if the line is truncated instead of
returning early. Return after handling headers, line numbers, etc., but
before printing the truncated clump.
* tests/pr/inf-loop.sh: New file.
* tests/local.mk (all_tests): Add the new test case.
* NEWS: Mention the bug fix.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-TMZPQ2AH.
2026-11-07 11:48:00 -08:00
Sylvestre Ledru a15203bb8c tests: wc: ensure -c counts all of a file when descriptors run out
Reported at https://github.com/uutils/coreutils/issues/15742

* tests/wc/page-size.sh: Add a test case.

Link: https://github.com/coreutils/coreutils/pull/446
2026-11-07 12:35:10 +00:00
Sylvestre Ledru 0201866781 tests: printf: ensure %q quotes C1 controls in names with apostrophes
Reported at https://github.com/uutils/coreutils/issues/15810

* tests/printf/printf-quote.sh: Add a test case.

Link: https://github.com/coreutils/coreutils/pull/445
2026-11-07 12:35:10 +00:00
Sylvestre Ledru d7e639418a tests: csplit: ensure -z removes only empty files it created
Reported at https://github.com/uutils/coreutils/issues/16068

* tests/csplit/csplit.sh: Add test cases.

Link: https://github.com/coreutils/coreutils/pull/444
2026-11-07 12:35:10 +00:00
Sylvestre Ledru 0f99186f24 tests: split: ensure the suffix start value is checked before reading
Reported at https://github.com/uutils/coreutils/issues/15569

* tests/split/numeric.sh: Add test cases.

Link: https://github.com/coreutils/coreutils/pull/443
2026-11-07 12:35:10 +00:00