Commit Graph
9437 Commits
Author SHA1 Message Date
Collin Funk 90d2b511e4 maint: touch: reduce variable scope
* src/touch.c (main): Declare variables where they are used instead of
at the start of the function.
2026-03-04 23:40:03 -08:00
Collin Funk e2e78f9e8e maint: chown,chgrp: reduce variable scope
* src/chown-core.c (describe_change, restricted_chown)
(change_file_owner, chown_files): Declare variables where they are used
instead of at the start of the function.
* src/chown.c (main): Likewise.
2026-03-04 23:34:45 -08:00
Collin Funk b7ff7e7c2c install: allow the combination of --compare and --preserve-timestamps
* NEWS: Mention the improvement.
* src/install.c (enum copy_status): New type to let the caller know if
the copy was performed or skipped.
(copy_file): Return the new type instead of bool. Reduce variable scope.
(install_file_in_file): Only strip the file if the copy was
performed. Update the timestamps if the copy was skipped.
(main): Don't error when --compare and --preserve-timestamps are
combined.
* tests/install/install-C.sh: Add some test cases.
2026-03-04 18:42:48 -08:00
Pádraig Brady b3fe24213e cksum: use more defensive escaping for --check
cksum --check is often the first interaction
users have with possibly untrusted downloads, so we should try
to be as defensive as possible when processing it.

Specifically we currently only escape \n characters in file names
presented in checksum files being parsed with cksum --check.
This gives some possibilty of dumping arbitrary data to the terminal
when checking downloads from an untrusted source.
This change gives these advantages:

  1. Avoids dumping arbitrary data to vulnerable terminals
  2. Avoids visual deception with ansi codes hiding checksum failures
  3. More secure if users copy and paste file names from --check output
  4. Simplifies programmatic parsing

Note this changes programmatic parsing, but given the original
format was so awkward to parse, I expect that's extremely rare.
I was not able to find example in the wild at least.
To parse the new format from from shell, you can do something like:

  cksum -c checksums | while IFS= read -r line; do
    case $line in
      *': FAILED')
        filename=$(eval "printf '%s' ${line%: FAILED}")
        cp -v "$filename" /quarantine
        ;;
    esac
  done

This change also slightly reduces the size of the sum(1) utility.
This change also apples to md5sum, sha*sum, and b2sum.

* src/cksum.c (digest_check): Call quotef() instead of
cksum(1) specific quoting.
* tests/cksum/md5sum-bsd.sh: Adjust accordingly.
* doc/coreutils.texi (cksum general options): Describe the
shell quoting used for problematic file names.
* NEWS: Mention the change in behavior.
Reported by: Aaron Rainbolt
2026-03-04 22:17:39 +00:00
Paul Eggert 69c0b63bea du: fflush after outputting a line
* src/du.c (print_size): Resurrect the fflush call, since there
can be significant delay between output lines.
2026-02-28 19:13:42 -08:00
Collin Funk 09a5449ff2 du: avoid locking and flushing standard output
This results in a noticeable increase in performance:

    $ yes /dev/null | head -n 10000000 | tr '\n' '\0' \
        | time --format=%E ./src/du-prev -l --files0-from=- > /dev/null
    0:20.40
    $ yes /dev/null | head -n 10000000 | tr '\n' '\0' \
        | time --format=%E ./src/du -l --files0-from=- > /dev/null
    0:16.57

* src/du.c (print_size): Prefer putchar and fputs which may be unlocked
unlike printf. Prefer ferror to fflush.
2026-02-27 22:22:20 -08:00
Paul Eggert d53203b316 stat: handle %%%N too
* src/stat.c (main): Fix incorrect counting of '%'s before 'N'.
* tests/stat/stat-fmt.sh: Test for the bug.
2026-02-27 16:50:36 -08:00
Paul Eggert d41e1375cb id: avoid unnecessary buffer flushing
* src/groups.c (main):
* src/id.c (main, print_stuff):
Don’t flush stdout before testing for write error.
Do the test only when in a loop, as a one-shot will
test for write error soon anyway.
2026-02-27 16:18:32 -08:00
Paul Eggert 02983e4935 cksum: prefer signed int
* src/cksum.c (min_digest_line_length, digest_hex_bytes)
(digest_length, md5_sum_stream, sha1_sum_stream)
(sha224_sum_stream, sha256_sum_stream, sha384_sum_stream)
(sha512_sum_stream, sha2_sum_stream, sha3_sum_stream)
(blake2b_sum_stream, sm3_sum_stream, problematic_chars)
(filename_unescape, valid_digits, bsd_split_3)
(algorithm_from_tag, split_3, digest_file, output_file)
(b64_equal, hex_equal, digest_check, main):
* src/cksum_avx2.c (cksum_avx2):
* src/cksum_avx512.c (cksum_avx512):
* src/cksum_crc.c (cksum_fp_t, cksum_slice8, crc_sum_stream)
(crc32b_sum_stream, output_crc):
* src/cksum_pclmul.c (cksum_pclmul):
* src/cksum_vmull.c (cksum_vmull):
* src/sum.c (bsd_sum_stream, sysv_sum_stream, output_bsd, output_sysv):
Prefer signed to unsigned int where either will do.
This allows better checking with -fsanitize=undefined.
It should also help simplify future patches, so that they
needn’t worry whether comparisons like ‘i < len - 2’ will misbehave.
2026-02-27 16:18:32 -08:00
Collin Funk 803bfa01e1 stat: don't check QUOTING_STYLE when --printf %%N is used
* NEWS: Mention the fix.
* src/stat.c (main): Only check QUOTING_STYLE if there is a %N that is
not preceded by a percentage sign.
* tests/stat/stat-fmt.sh: Add some test cases.
2026-02-26 21:20:37 -08:00
Collin Funk 4195e36664 id: promptly diagnose write errors
* NEWS: Mention the improvement.
* src/id.c (print_stuff): Call fflush for each listed user to check for
write errors.
* tests/misc/io-errors.sh: Add an invocation of 'id'.
2026-02-26 19:07:21 -08:00
Collin Funk 80b229be71 groups: promptly diagnose write errors
* NEWS: Mention the improvement.
* src/groups.c (main): Call fflush for each listed user to check for
write errors.
* tests/misc/io-errors.sh: Add an invocation of 'groups'.
2026-02-26 19:05:32 -08:00
Collin Funk 89735ea830 shuf: avoid locking standard output when using --input-range
Here is the throughput before this patch:

    # write_permuted_numbers
    $ ./src/shuf-prev -i 0-100000000 | pv -r > /dev/null
    [ 153MiB/s]

    # write_random_numbers
    $ timeout 10 ./src/shuf-prev -i 0-100000 -r | pv -r > /dev/null
    [78.6MiB/s]

Here is the throughput after this patch:

    # write_permuted_numbers
    $ timeout 10 ./src/shuf -i 0-100000000 | pv -r > /dev/null
    [ 308MiB/s]

    # write_random_numbers
    $ timeout 10 ./src/shuf -i 0-100000 -r | pv -r > /dev/null
    [ 196MiB/s]

* NEWS: Mention the performance improvement.
* src/shuf.c (write_permuted_numbers, write_random_numbers): Prefer
fputs and fputc which may be unlocked over printf which locks standard
output.
2026-02-21 19:20:07 -08:00
Collin Funk 992da4574a maint: printf: prefer static initialization
* src/printf.c (main): Remove unnecessary initialization.
2026-02-19 21:42:35 -08:00
Collin Funk 395fcca795 maint: fmt: prefer static initialization
* src/fmt.c (prefix, max_width): Initialize variables.
(main): Remove unnecessary initializations.
2026-02-19 21:40:44 -08:00
Collin Funk 6bf6d52e54 maint: sort: prefer static initialization
* src/sort.c (main): Remove unnecessary initialization.
2026-02-19 21:37:15 -08:00
Collin Funk 96e39300b1 maint: df: prefer static initialization
* src/df.c (human_output_opts, grand_fsu): Initialize variables.
(main): Remove unnecessary initializations.
2026-02-19 21:34:03 -08:00
Collin Funk a24b3075c3 maint: split: prefer static initialization
* src/split.c (outbase, infile): Initialize variables.
(main): Remove unnecessary initializations.
2026-02-19 21:28:40 -08:00
Collin Funk 26c92a62c6 maint: tail: prefer static initialization
* src/tail.c (count_lines, line_end): Initialize variables.
(main): Remove unnecessary initializations.
2026-02-19 21:24:54 -08:00
Collin Funk cc87809aae maint: csplit: prefer static initialization
* src/csplit.c (prefix, remove_files): Initialize variables.
(main): Remove unnecessary initializations.
2026-02-19 21:22:17 -08:00
Collin Funk dc0baaf4de maint: comm: prefer static initialization
* src/comm.c (only_file_1, only_file_2, both): Initialize variables.
(main): Remove unnecessary initializations.
2026-02-19 21:18:41 -08:00
Collin Funk ecf3f98eec maint: wc: prefer static initialization
* src/wc.c (main): Remove unnecessary initializations.
2026-02-19 21:11:27 -08:00
Collin Funk 85dde4c2d9 maint: tac: prefer static initialization
* src/tac.c (separator, separator_ends_record, sentinel_length):
Initialize variables.
(main): Remove unnecessary initializations.
2026-02-19 21:08:43 -08:00
Collin Funk fea1dcadf6 maint: join: prefer static initialization
* src/join.c (print_pairables): Initialize variable.
(main): Remove unnecessary initializations.
2026-02-19 21:05:11 -08:00
Collin Funk 425dd90b88 maint: cut: prefer static initialization
* src/cut.c (main): Remove unnecessary initializations.
2026-02-19 21:01:10 -08:00
Collin Funk 82a20cd6f2 maint: seq: prefer static initialization
* src/seq.c (separator): Initialize variable.
(main): Remove unnecessary initializations.
2026-02-19 20:53:20 -08:00
Collin Funk ef72d0edd2 maint: paste: prefer static initialization
* src/paste.c (main): Remove unnecessary initializations.
2026-02-19 20:49:40 -08:00
Collin Funk 70e4e2d43a maint: install: prefer static initialization
* src/install.c (main): Remove unnecessary initializations.
2026-02-19 20:45:54 -08:00
Collin Funk beb9392206 maint: chmod: prefer static initialization
* src/chmod.c (main): Remove unnecessary initializations.
2026-02-19 20:39:41 -08:00
Collin Funk 5b29c9c04f maint: head: prefer static initialization
* src/head.c (line_end): Initialize variable.
(main): Remove unnecessary initializations.
2026-02-19 20:36:56 -08:00
Collin Funk 97b7213118 maint: ln: prefer static initialization
* src/ln.c (main): Remove unnecessary initializations.
2026-02-19 20:36:47 -08:00
Collin Funk 4bb3309b72 maint: nl: prefer static initialization
* src/nl.c (main): Remove unnecessary initialization.
2026-02-19 20:36:40 -08:00
Collin Funk 1197e54553 maint: touch: prefer static initialization
* src/touch.c (main): Remove unnecessary initializations.
2026-02-19 20:36:31 -08:00
Collin Funk f009f68e3b maint: fold: prefer static initialization
* src/fold.c (main): Remove unnecessary initializations.
2026-02-19 20:36:08 -08:00
Collin Funk a398d52b65 maint: tee: prefer static initialization
* src/tee.c (main): Remove unnecessary initializations.
2026-02-19 20:35:49 -08:00
Collin Funk 66d34782b9 maint: rmdir: prefer static initialization
* src/rmdir.c (main): Remove unnecessary initialization.
2026-02-19 20:35:35 -08:00
Collin Funk 300ef2e63b maint: tty: prefer static initialization
* src/tty.c (main): Remove unnecessary initialization.
2026-02-19 20:35:19 -08:00
Collin Funk 6a3dde5dd2 wc: add aarch64 Neon optimization for wc -l
Here is an example of the performance improvement:

    $ yes abcdefghijklmnopqrstuvwxyz | head -n 100000000 > input
    $ time ./src/wc-prev -l < input
    100000000

    real	0m0.793s
    user	0m0.630s
    sys	0m0.162s
    $ time ./src/wc -l < input
    100000000

    real	0m0.230s
    user	0m0.065s
    sys	0m0.164s

* NEWS: Mention the performance improvement.
* gnulib: Update to the latest commit.
* configure.ac: Check the the necessary intrinsics and functions.
* src/local.mk (noinst_LIBRARIES) [USE_NEON_WC_LINECOUNT]: Add
src/libwc_neon.a.
(src_libwc_neon_a_SOURCES, wc_neon_ldadd, src_libwc_neon_a_CFLAGS)
[USE_NEON_WC_LINECOUNT]: New variables.
(src_wc_LDADD) [USE_NEON_WC_LINECOUNT]: Add $(wc_neon_ldadd).
* src/wc.c [USE_NEON_WC_LINECOUNT]: Include sys/auxv.h and asm/hwcap.h.
(neon_supported) [USE_NEON_WC_LINECOUNT]: New function.
(wc_lines) [USE_NEON_WC_LINECOUNT]: Use neon_supported and
wc_lines_neon.
* src/wc.h (wc_lines_neon): Add declaration.
* src/wc_neon.c: New file.
* doc/coreutils.texi (Hardware Acceleration): Document the "-ASIMD"
hwcap and the variable used in ./configure to override detection of Neon
instructions.
* tests/wc/wc-cpu.sh: Also add "-ASIMD" to disable the use of Neon
instructions.
2026-02-18 20:09:44 -08:00
Collin Funk 9edebc617f maint: expr: reduce variable scope
* src/expr.c (mbs_logical_cspn, main, trace, docolon, eval7, eval6)
(eval5, eval4, eval3, eval2, eval1, eval): Declare variables where they
are used instead of at the start of the function.
2026-02-17 18:45:33 -08:00
Chris Down 41e5ae80b1 pwd: fix heap buffer overflow in file_name_prepend
file_name_prepend works by right-aligning path data in a growing buffer.
When the buffer is too small, it then allocates a new buffer via
xpalloc() and copies existing data to the end of the new buffer.

Unfortunately, the memcpy destination is computed as buf + p->n_alloc -
n_free, but xpalloc has already updated p->n_alloc to the new (larger)
allocation size while n_free still reflects the old state. This places
the data at too high an offset, writing past the end of the buffer.

Update to properly calculate the destination offset.

Fixes: v9.5-171-g61ab25c35 ("pwd: prefer xpalloc to xnrealloc")
2026-02-16 10:45:45 +00:00
Collin Funk 131fad77ad maint: seq,who: prefer xasprintf
* src/seq.c (main): Use xasprintf instead of asprintf followed by a
check if the allocation fails.
* src/who.c (print_line): Likewise.
2026-02-14 14:48:45 -08:00
Collin Funk 84c2848f5d maint: seq: reduce variable scope
* src/seq.c (long_double_format, print_numbers, main): Declare variables
where they are used instead of at the start of the function.
2026-02-14 12:15:09 -08:00
Pádraig Brady 8732e7e95e tests: getlimits: output error strings
* src/getlimits.c (main): Iterate over defined errnos,
and output shell compatible error strings.
* tests/Coreutils.pm: Adjust so shell quotes are stripped.
2026-02-10 12:24:17 +00:00
Collin Funk 224b90e603 maint: pinky: reduce variable scope
* src/pinky.c (create_fullname, idle_string, print_entry)
(print_long_entry, main): Declare variables where they are used instead
of at the start of the function. Initialize variables where they are
declared.
2026-02-09 22:30:48 -08:00
Collin Funk 6bbf04db63 nl: support multi-byte section delimiters
* NEWS: Mention the improvement.
* src/nl.c: Include mcel.h.
(DEFAULT_SECTION_DELIMITERS): Resize to fit 2 multi-byte characters.
(section_del_len): New variable.
(check_section): Compare against section_del_len instead of 2.
(main): Support multi-byte characters for the -d option.
* tests/nl/multibyte.sh: New file.
* tests/nl/nl.sh: New file, moved from tests/misc/nl.sh.
* tests/local.mk (all_tests): Add the new test. Adjust the existing
tests file name.
* cfg.mk (exclude_file_name_regexp--sc_space_tab): Adjust Adjust the
existing tests file name.
2026-02-08 18:45:24 -08:00
Dr. David Alan Gilbert eaac58cffa maint: unexpand: remove dead store
The assign to next_tab_column in the backspace branch is never
read; in fact it's always written and then read solely inside the
blank branch.

Move the declaration of 'next_tab_column' down into the blank
branch, and remove its assignment in the backspace branch.

Spotted by the 'infer' static checker.

* src/unexpand.c (unexpand): Remove dead store of next_tab_column.
2026-02-06 14:43:24 +00:00
Pádraig Brady ddb8b78a2c doc: pr: use -COLS consistently
Help this back from release as would break a couple of translations.

* src/pr.c: Use COLS rather than COLUMN consistently
in comments and usage().
2026-02-06 13:37:58 +00:00
Collin Funk ddfe86bddf stat,df: remove an unnecessary alloca
* src/find-mount-point.c (find_mount_point): Don't call ASSIGN_STRDUPA
on the result of dir_name.
2026-02-04 16:42:26 -08:00
Pádraig Brady 32a5bf1ead doc: improve highlighting of dd --help translations
* src/system.h (oputs_): Ensure we're not matching '-' in
translated descriptions.  Also support highlighting only
dd "foo=bar" when the description is separated with a single space.
2026-01-31 22:08:09 +00:00
Pádraig Brady 18811574a2 maint: avoid prohibit-const-char syntax check failure
* src/copy.c: Avoid prohibit-const-char failure,
newly triggered by the (correct) recent adjustment.
2026-01-30 14:12:12 +00:00