Pádraig Brady [Mon, 11 Nov 2024 19:54:18 +0000 (19:54 +0000)]
tests: avoid false failure with --disable-selinux
* tests/ls/selinux-segfault.sh: Move recent addition to ...
* tests/ls/selinux.sh: ... this new test that uses require_selinux_
to skip appropriately when we've built without selinux support.
Also add a non root test that checks we output '.' along with the
mode for files, to indicate a security context is present.
* tests/local.mk (Reference the new test).
Paul Eggert [Mon, 11 Nov 2024 16:52:12 +0000 (08:52 -0800)]
build: update gnulib submodule to latest
This also fixes a problem with ls -Z when configured with
--disable-acl, reported by Pádraig Brady
<https://bugs.gnu.org/73418#52>.
* src/ls.c (gobble_file): Pass ACL_GET_SCONTEXT to
file_has_aclinfo, if -Z is used.
Paul Eggert [Sun, 10 Nov 2024 00:51:02 +0000 (16:51 -0800)]
ls: add test case for ls -Z bug
Problem reported by Pádraig Brady <https://bugs.gnu.org/73418#35>.
This bug was fixed by the recent gnulib update.
* tests/ls/selinux-segfault.sh:
Also test for ls -Z on broken symlinks.
Pádraig Brady [Sat, 9 Nov 2024 16:55:33 +0000 (16:55 +0000)]
tests: avoid false failure on older valgrind
* src/shuf.c (main): In dev mode call randint_all_free()
to avoid false failure with valgrind 3.16.1 at least.
Note this partially reinstates commit v9.0-109-g0106b5a4b.
This was noticed on a debian 11 system running CI tests.
Paul Eggert [Sat, 9 Nov 2024 04:17:54 +0000 (20:17 -0800)]
seq: use full_write instead of fwrite
* src/seq.c: Include full-write.h.
(seq_fast): Since we’re doing all the buffering work anyway,
we might as well use syscalls instead of stdio to write.
Use full_write instead of fwrite.
Paul Eggert [Sat, 9 Nov 2024 03:55:54 +0000 (19:55 -0800)]
seq: simplify output buffer management
* src/seq.c (seq_fast): Simplify by using an output buffer of
known size (BUFSIZ) on the stack, rather than a heap buffer that
might grow. For the number buffer, don’t bother appending NUL
since nobody uses the NUL, and xpalloc from nullptr not p0 since
we need to move the buffer data by hand anyway.
Paul Eggert [Fri, 8 Nov 2024 17:35:35 +0000 (09:35 -0800)]
seq: explicate incr
* src/seq.c (incr): Change API to make the code easier to follow,
and also to avoid undefined behavior on hypothetical platforms
where '9' == INT_MAX (!). Caller changed.
Paul Eggert [Fri, 8 Nov 2024 08:01:01 +0000 (00:01 -0800)]
shuf: prefer xpalloc to xnrealloc
* src/shuf.c (RESERVOIR_LINES_INCREMENT): Remove.
All uses removed.
(read_input_reservoir_sampling, main):
Prefer idx_t to size_t for sizes related to xpalloc.
(read_input_reservoir_sampling): Prefer xpalloc to xnrealloc.
Paul Eggert [Fri, 8 Nov 2024 07:24:14 +0000 (23:24 -0800)]
pwd: prefer xpalloc to xnrealloc
* src/pwd.c (struct file_name, file_name_prepend):
Prefer idx_t to size_t for sizes related to xpalloc,
(file_name_init): Don’t overflow if PATH_MAX == INT_MAX.
(file_name_prepend): Prefer xpalloc to by-hand resizing.
Simplify by using memcpy return value.
Paul Eggert [Fri, 8 Nov 2024 06:56:44 +0000 (22:56 -0800)]
du: prefer xpalloc to xnrealloc
* src/du.c (prev_level, process_file):
Prefer idx_t to size_t for sizes related to xpalloc,
and to nesting levels (since that’s what fts_level does anyway).
(process_file): Prefer xpalloc to xnrealloc.
Paul Eggert [Fri, 8 Nov 2024 06:45:32 +0000 (22:45 -0800)]
df: prefer xpalloc to xnrealloc
* src/df.c (ncolumns, nrows, print_table, get_header, get_dev):
Prefer idx_t to size_t for sizes related to xpalloc.
(ncolumns_alloc, nrows_alloc): New static vars.
(alloc_table_row, alloc_field): Prefer xpalloc to xnrealloc.
Paul Eggert [Fri, 8 Nov 2024 00:39:35 +0000 (16:39 -0800)]
pr: prefer xpalloc to x2realloc
* src/pr.c (buff_allocated, main):
Prefer idx_t to size_t for sizes.
(main, store_char): Use xpalloc, not x2realloc.
(init_store_cols): Check for multiplication overflow ourselves
and use ximalloc, not xnmalloc. This is a bit simpler.
* src/system.h (X2REALLOC): Remove; no longer used.
Paul Eggert [Thu, 7 Nov 2024 22:17:14 +0000 (14:17 -0800)]
cut,numfmt: prefer xpalloc to x2nrealloc
* src/set-fields.c (n_frp, n_frp_allocated, complement_rp, set_fields):
Prefer idx_t to ptrdiff_t/size_t for nonnegative sizes.
(add_range_pair): Use xpalloc, not x2nrealloc.
Paul Eggert [Thu, 7 Nov 2024 22:09:26 +0000 (14:09 -0800)]
ptx: prefer xpalloc to x2nrealloc
* src/ptx.c (line_width, gap_size, WORD, WORD_TABLE)
(maximum_word_length, reference_max_width, occurs_alloc)
(number_of_occurs, half_line_width, truncation_string_length)
(compare_words, search_table, digest_word_file)
(find_occurs_in_text, fix_output_parameters)
(generate_all_output, main, find_occurs_in_text)
(fix_output_parameters, generate_all_output):
Prefer idx_t to ptrdiff_t/size_t for nonnegative sizes.
(first, second): Remove macros, replacing them with locals.
(search_table): Use hi (for highest + 1) to simplify.
Avoid unlikely overflow by not computing lo + hi.
(digest_word_file, find_occurs_in_text): Use xpalloc, not x2nrealloc.
Paul Eggert [Thu, 7 Nov 2024 20:58:49 +0000 (12:58 -0800)]
od: prefer xpalloc to x2nrealloc
* src/od.c (n_specs, n_specs_allocated, write_block, get_lcm, main):
Use idx_t instead of size_t for some sizes, so that we can
use xpalloc.
(decode_format_string): Prefer xpalloc to X2NREALLOC.
Paul Eggert [Thu, 7 Nov 2024 20:51:04 +0000 (12:51 -0800)]
expand: check for colno overflow
* src/expand-common.c (get_next_tab_column): Check for tab
stop overflow here. All callers changed to not check.
* src/expand.c (expand): Use colno for column number.
Paul Eggert [Thu, 7 Nov 2024 20:32:21 +0000 (12:32 -0800)]
ls: fix aclinfo cache bug
Found when testing on a new platform with a new file system.
* src/ls.c (file_has_aclinfo_cache): For failures, also cache
return value, scontext, and scontext_err, and when using cached
values make sure buf and size have reasonable values for
aclinfo_free etc.
Paul Eggert [Thu, 7 Nov 2024 16:57:42 +0000 (08:57 -0800)]
ls: use Gnulib’s unsupported errno list
* bootstrap.conf (gnulib_modules): Add acl-permissions, which
supplies acl_errno_valid, and which we are already using
indirectly via file-has-acl.
* src/ls.c (errno_unsupported): Remove. All calls replaced
by !acl_errno_valid.
Paul Eggert [Thu, 7 Nov 2024 01:56:15 +0000 (17:56 -0800)]
expand: refactor to introduce ‘colno’
* src/expand-common.h (colno): New typedef.
All uses of uintmax_t for column numbers replaced by colno.
* src/expand-common.c (add_tab_stop): Use xpalloc
instead of X2NREALLOC, and use ckd_add to check for overflow.
Paul Eggert [Thu, 7 Nov 2024 00:31:18 +0000 (16:31 -0800)]
expand: prefer xpalloc to x2nrealloc
* src/expand-common.c (max_column_width, n_tabs_allocated)
(first_free_tab, add_tab_stop, parse_tab_stops, validate_tab_stops)
(get_next_tab_column):
Use idx_t for sizes. All uses changed.
(add_tab_stop): Use xpalloc instead of X2NREALLOC.
Use ckd_add to check for overflow, instead of doing it by hand.
Paul Eggert [Thu, 7 Nov 2024 00:16:25 +0000 (16:16 -0800)]
maint: expand heap a bit less aggressively
* gl/lib/heap.c (struct heap, heap_alloc, heap_insert)
(heapify_down, heapify_up): Prefer idx_t to size_t for sizes.
(heap_insert): Use xpalloc instead of x2nrealloc.
(heapify_down): Return void since no caller cares about value.
* gl/modules/heap: Depend on idx.
* bootstrap.conf: Explicitly depend on the crc module.
* doc/coreutils.texi (cksum): Add "crc32b" as an argument to -a.
* src/cksum.c (crc32b_sum_stream): A new function similar to
crc_sum_stream, but which does not include the length in
the CRC calculation.
* src/cksum.h: Add crc32b_sum_stream prototype.
* src/digest.c: Add "crc32b" as an argument to -a.
* tests/cksum/cksum.sh: Refactor to test both crc and crc32b.
* tests/cksum/cksum-a.sh: Add "crc32b" case.
* tests/cksum/cksum-base64.pl: Likewise.
* tests/misc/read-errors.sh: Likewise.
* NEWS: Mention the new feature.
Pádraig Brady [Fri, 1 Nov 2024 12:42:41 +0000 (12:42 +0000)]
doc: fix timeout --help for -p
* src/timeout.c (usage): Fix typo of period with comma.
* tests/timeout/timeout.sh: Only test a single option variant,
as tests/misc/usage_vs_getopt.sh suffices for basic option validation.
Pádraig Brady [Wed, 30 Oct 2024 12:45:58 +0000 (12:45 +0000)]
timeout: add -f and -p short options as per POSIX 2024
* src/timeout.c: Support -f and -p short options, corresponding to
--foreground and --preserve-status respectively. This adds
compatability with POSIX 2024 and OpenBSD.
(usage): Separate translations, and reorder the option descriptions.
* doc/coreutils.texi (timeout invocation): Adjust accordingly,
and also reorder the option descriptions alphabetically.
* tests/timeout/timeout.sh: Also test short option variants.
Pádraig Brady [Mon, 14 Oct 2024 12:06:44 +0000 (13:06 +0100)]
maint: add syntax-check to ensure all gl/ files are distributed
* cfg.mk (sc_gldist_missing): Add a new target to ensure we don't
forget to distribute any new gl/ files.
* gl/local.mk: Remove generation comment since it's
now encapsulated in the syntax-check, which outputs a consumable
diff to make any future adjustments.
Also adjust ordering to that of the C locale used in the syntax check.
Pádraig Brady [Thu, 3 Oct 2024 11:32:45 +0000 (12:32 +0100)]
tests: ls: don't always skip a capability test
* tests/ls/no-cap.sh: Move to being a root only test, since
commit v9.5-132-g2a6bed933 we now need to call setcap
to make the test effective. Otherwise we would have always
just skipped the test.
Paul Eggert [Thu, 3 Oct 2024 04:11:02 +0000 (21:11 -0700)]
ls: tune usage of getxattr/stat syscalls
Update gnulib submodule to latest. This changes the file_has_aclinfo
API, so at the same time do the following changes to ls.c, which
adjusts to these changes among other things.
* src/ls.c (filetype_d_type, d_type_filetype): New static constants.
(format_needs_capability): New static var.
(main): Set and use it. Don’t set format_needs_stat merely
because print_scontext, as we needn’t call stat to get the
scontext. Instead, set format_needs_type if print_scontext but
not format_needs_stat.
(print_dir): Use new static tables to determine filetype
more efficiently.
(file_has_aclinfo_cache): Adjust to Gnulib file_has_aclinfo API change.
(gobble_file): Check stat if format_needs_type but the type is
unknown. Be conservative, and when deciding whether to check stat
but the type is unknown, assume it might be directory. Similarly
for normal files when classifying; if the type is unknown assume
it might be normal. Use new static constants and IFTODT to
compute filetype more straightforwardly. Get ACLs and check for
capability less often.
(get_color_indicator): Omit unnecessary call to is_colored (C_CAP),
since f->has_capability can be true only if is_colored (C_CAP).
Paul Eggert [Wed, 2 Oct 2024 18:22:03 +0000 (11:22 -0700)]
ls: omit cast from gobble_file
* src/ls.c (gobble_file): Minor refactoring. Last arg is now null
pointer, not "", for no directory. All callers changed.
Avoid need for cast from char const * to char *.
Paul Eggert [Tue, 1 Oct 2024 20:35:50 +0000 (13:35 -0700)]
ls: omit some unnecessary NULs
* src/ls.c (BIN_STR): New macro, replacing LEN_STR_PAIR.
All uses changed. This avoids the need to store the
trailing \0 in each string. This change is more for clarity,
to make it clear the \0 is not needed.
Pádraig Brady [Wed, 2 Oct 2024 21:57:16 +0000 (22:57 +0100)]
ls: reinstate capability checking in more cases
The recent commit v9.5-119-g4ce432ad8 restricted capability checking
to only files with XATTR_NAME_CAPS set. If this is done then we need
to adjust tests/ls/no-cap.sh so that it doesn't always skip. More
problematically XATTR_NAME_CAPS was only determined in long listing
mode, thus breaking capability coloring in short listing mode
as evidenced by the failing tests/ls/capability.sh test.
Note capability checking does have a large overhead, but we've
disabled capability checking by default anyway through the default
color configuration since v9.0-187-g6b5134770
So for these reasons revert to checking capabilities as before.
* src/ls.c (gobble_file): Check for capabilities in all modes
if enabled in color config.
Pádraig Brady [Wed, 2 Oct 2024 15:33:42 +0000 (16:33 +0100)]
tests: fix skipping of mtab simulation tests
Where rpl_fopen() is used rather than fopen(),
wrapping fopen() is ineffective.
Note rpl_fopen() is used as of glibc-2.39 at least
(due to fflush and fclose being replaced).
* tests/df/no-mtab-status.sh: Wrap open() rather than fopen().
* tests/df/skip-duplicates.sh: Likewise.
Bernhard Voelker [Sun, 29 Sep 2024 16:27:00 +0000 (18:27 +0200)]
maint: avoid sc_preprocessor_indentation failure in factor.c
Prompted by the following 'make syntax-check' failure:
cppi: src/factor.c: line 175: not properly indented
cppi: src/factor.c: line 176: not properly indented
maint.mk: incorrect preprocessor indentation
make: *** [cfg.mk:750: sc_preprocessor_indentation] Error 1
Paul Eggert [Mon, 30 Sep 2024 05:04:02 +0000 (22:04 -0700)]
ls: use fewer xattr-related syscalls
* src/ls.c: Do not include <selinux/selinux.h> or "smack.h".
Include <linux/attr.h> if HAVE_LINUX_ATTR_H, for XATTR_NAME_CAPS.
(free_ent): Use aclinfo_scontext_free to free f->scontext.
(getfilecon_cache): Remove; no longer needed.
(file_has_aclinfo_cache): Rename from file_has_acl_cache,
and use file_has_aclinfo instead of file_has_acl. All uses changed.
(gobble_file): Use file_has_aclinfo instead of file_has_acl, so
that we get more info about the file before deciding whether to
issue further syscalls for it. Let file_has_aclinfo worry about
smack and SELinux. Call has_capability only if the xattr list
mentions XATTR_NAME_CAPS.
Paul Eggert [Fri, 27 Sep 2024 23:16:43 +0000 (16:16 -0700)]
factor: eliminate print_uuint recursion
* src/factor.c (lbuf_putint_append): New function, with
most of the old lbuf_putint body. Do the umaxtostr stuff
by hand so that we needn’t worry about the trailing NUL.a
Do the string copy by hand since the string is so short.
(lbuf_putint): Reimplement in terms of lbuf_putint_append.
Omit last arg, which is no longer needed. All callers changed.
(print_uuint): Rewrite to avoid recursion, using
lbuf_putint_append for the usual case.
Paul Eggert [Fri, 27 Sep 2024 03:20:05 +0000 (20:20 -0700)]
factor: macro refactoring
* src/factor.c (W_TYPE_SIZE): Simplify by always defining
to UINTMAX_WIDTH.
(W): Remove. All uses replaced by W_TYPE_SIZE.
We no longer need one of its static_asserts.
Paul Eggert [Fri, 27 Sep 2024 03:01:58 +0000 (20:01 -0700)]
factor: improve gmp-related buffering
Previously, the code used stdio buffers for gmp numbers,
and did its own buffering for smaller numbers. This meant
for more flushing than was needed. The code now uses its
own buffering for all standard output, which makes for
less flushing and fewer writes.
* src/factor.c (lbuf_half_flush): New function, taken from the
body of lbuf_putnl.
(lbuf_putnl): Use it.
(lbuf_putmpz): New function, to output an mpz without using stdio.
(print_factors): Output via functions instead of via stdio.
Paul Eggert [Thu, 26 Sep 2024 22:36:44 +0000 (15:36 -0700)]
factor: improve fd buffering
* src/factor.c (struct lbuf_, lbuf, lbuf_alloc): Remove.
All uses removed.
(FACTOR_PIPE_BUF): Now a constant instead of a macro.
Increase to PIPE_BUF if available.
(lbuf_buf, lbuffered): New static vars, replacing lbuf.
All uses changed.
(lbuf_flush): Avoid unlikely recursion on write failure.
(lbuf_putc): Now simply adds a byte to the buffer.
(lbuf_putnl): Do the work of the old lbuf_putc ('\n').
Use changed. Use memrchr to find the newline.
(lbuf_putint): Widths are now int, not size_t.
Paul Eggert [Thu, 26 Sep 2024 17:25:51 +0000 (10:25 -0700)]
factor: mod2 now returns uuint
* src/factor.c (uuset): New function.
(mod2): Return uuint rather than having half the returned value
stored via a pointer. This makes the code a bit easier to read
and can help the compiler avoid aliasing issues. All callers changed.
Paul Eggert [Thu, 26 Sep 2024 16:31:35 +0000 (09:31 -0700)]
factor: new type uuint
This refactors to add a new type, a uintmax_t pair, which
can simplify some code without slowing it down.
* src/factor.c (uuint): New type.
(lo, hi, hiset, make_uuint): New functions.
(struct factors.plarge): Use the new type. All uses changed.
Paul Eggert [Wed, 25 Sep 2024 23:53:52 +0000 (16:53 -0700)]
factor: switch to stdc_leading_zeros etc
* bootstrap.conf (gnulib_modules): Add stdc_trailing_zeros.
* cfg.mk (_gl_TS_unmarked_extern_vars): Remove factor_clz_tab,
as it’s no longer present.
* src/factor.c: Include stdbit.h.
(__clz_tab, factor_clz_tab): Remove.
(ASSERT, UHWtype, __GMP_DECLSPEC): Use simpler way to pacify
-Wunused-macros.
(count_leading_zeros, count_trailing_zeros):
Remove. All uses replaced by stdc_leading_zeros, stdc_trailing_zeros.
(factor_using_division, prime2_p): Add a couple of ‘assume’s
so that GCC knows the stdc_* calls are nonzero and can
optimize accordingly.
Paul Eggert [Wed, 25 Sep 2024 22:59:09 +0000 (15:59 -0700)]
factor: port to platforms
* src/factor.c (mod2): Work even if cntd <= cnta. The old version
of the code assumed that shifts by N had unspecified behavior
unless 0 <= N < wordsize. Although this assumption is portable to
all known practical platforms, the C standard says these shifts
have undefined behavior and some pedantic platforms check this.
* tests/factor/create-test.sh:
* tests/local.mk (factor_tests): New test t37.
* src/sort.c (usage): Don't mention the ambiguous "manual",
rather "full documentation", echoing the language at the
bottom of each coreutils man page.
Fixes https://bugs.gnu.org/72914
* man/env.x: Avoid confusion in the [OPTIONS] section
by renaming to [SCRIPT OPTION HANDLING], and removing info
regarding default signal handling, which is best
restricted to the full info manual.
Addresses https://bugs.gnu.org/72914
* src/echo.c (usage): Use printf(1) rather than 'printf',
which is marked up more appropriately, and can be
referenced by some man page readers.
Fixes https://bugs.gnu.org/72914
* src/printf.c (print_formatted): Add support for %i$ indexed args.
* tests/printf/printf-indexed.sh: Add a new file of test cases.
* tests/local.mk: Reference the new test file.
* doc/coreutils.texi (printf invocation): Mention how mixed
processing of indexed and sequential references are supported,
unlike the printf(2) library function.
* NEWS: Mention the new (POSIX:2024) feature.
Addresses https://bugs.gnu.org/73068
Pádraig Brady [Wed, 28 Aug 2024 11:33:17 +0000 (12:33 +0100)]
all: fix error checking in gl/lib/xdectoint.c
This issue was noticed with -flto on GCC 14.2.1
* gl/lib/xdectoint.c (__xnumtoint): Only inspect the
returned value if LONGINT_INVALID is not set,
as the returned value is uninitialized in that case.
Fixes https://bugs.gnu.org/72842