Commit Graph
5018 Commits
Author SHA1 Message Date
Max AmbaumandGitHub 912471d40a od: hex byte offset case fix (#12175)
* Made hex byte offset lowercase

* Added test based on issue

* Fixed formatting, moved import to local scope

* Fixed failing tests

* Forced no wasi test

* Revert "Forced no wasi test"

This reverts commit 0cd71c69bf.

* Switched linux to unix, to match test_dd

* Removed urandom dependency credit @cakebaker
2026-05-07 17:28:46 +02:00
Daniel Hofstetter 10e3a9c3b8 tests,stdbuf: adapt to change in ctor 2026-05-07 09:44:53 +02:00
Daniel HofstetterandDorian Péron bf75238336 md5sum: remove some stderr_is("") in the tests 2026-05-06 18:07:20 +02:00
oech3andDaniel Hofstetter 37c42a29ca id: replace nix by rustix 2026-05-06 17:52:38 +02:00
Dorian PéronandDaniel Hofstetter f665b63cc4 cksum: Fix --check filename escaping for 9.11 2026-05-06 17:21:34 +02:00
Sylvestre LedruandDorian Péron bd170a5d4b cp: strip setuid/setgid when chown fails during -p (#9750)
When `cp -p` cannot chown the destination to the source's owner
(e.g. a non-root user copying a root-owned setuid file), GNU cp
strips the setuid and setgid bits from the applied mode so the
destination does not give the copying user elevated privileges via
the copy. uutils was unconditionally applying the source mode,
producing user-owned files with a live setuid bit.

Track `ownership_preserved` alongside the existing chown retry
logic and, in the subsequent `handle_preserve(mode, ...)` block,
mask off `0o6000` from the source's mode when ownership could not
be preserved. The sticky bit (01000) is kept, matching GNU.
2026-05-06 11:47:38 +02:00
Sylvestre LedruandDorian Péron 7ba1bf857c cp: don't preserve xattrs with -p by default (#9704)
GNU `cp -p` preserves mode, ownership, and timestamps. xattrs are
NOT preserved unless the user asks for them via `--preserve=xattr`
or `-a`. uutils's `Attributes::DEFAULT` had xattr set to
`Preserve::Yes { required: true }`, which (1) diverges from GNU and
breaks scripts that expect the stock behavior, (2) leaks security
xattrs like file capabilities and SELinux labels into copies when
run as root, and (3) fails hard on destinations that don't support
xattrs.

Remove the xattr override in `Attributes::DEFAULT` so it inherits
`Preserve::No` from `Attributes::NONE`. `Attributes::ALL` (used by
`-a` and `--preserve=all`) still sets xattr to Yes, and
`--preserve=xattr` still works as before.
2026-05-06 11:47:38 +02:00
Sylvestre LedruandDorian Péron ef5d752282 cp: open source and dest with O_NOFOLLOW in no-dereference mode (#10017)
In `-P` / no-dereference mode, cp now opens the source file with
`O_NOFOLLOW`, matching GNU cp. This closes a TOCTOU window where an
attacker who can swap the source path between cp's `lstat` check and
the subsequent open could redirect the read through a symlink to a
sensitive file (e.g. /etc/shadow). With `O_NOFOLLOW` the open fails
with `ELOOP` instead.

The same flag is propagated to `safe_copy::create_dest_restrictive`,
so the destination open also refuses to follow a symlink in
no-dereference mode. Without that, an attacker who plants the dest
path as a symlink between the caller's check and the open could
redirect the truncate (and the subsequent write) to any file the
caller has permission to write — the symmetric attack to the source
side. With `nofollow=true` the dest open returns `ELOOP` and the
victim file is left untouched.

`copy_on_write` gains a `nofollow` parameter threaded from
`copy_helper`, set to `!options.dereference(source_in_command_line)`.
In deref mode the flag is false and behavior is unchanged — cp still
follows symlinks, matching GNU.

Extends `util/check-safe-traversal.sh` with a cp -P strace check so
the invariant is locked in: future changes that drop `O_NOFOLLOW`
here will fail the smoke test.
2026-05-06 11:47:38 +02:00
Sylvestre LedruandDorian Péron 681030bca3 cp: create destination with restrictive 0o600 initial mode (#10011)
cp previously created the destination with mode 0o666 masked by umask
(typically 0o644), then later applied the final permissions via
set_permissions. In a shared directory like /tmp this opened an
observable window where another user could open the destination with
the intermediate broad mode before cp narrowed it, leaking file
contents that were intended to stay private.

Create dest with 0o600 initially in every non-symlink code path —
clone, sparse_copy, sparse_copy_without_hole, fs_copy, the stream
path, and the non-Linux fs::copy fallback. The existing
set_permissions call in copy_file applies the real final mode after
the content is written, so user-visible end state is unchanged; only
the intermediate mode is tightened. Matches GNU cp.

Extend `util/check-safe-traversal.sh` with a cp strace check that
asserts the destination openat carries mode 0600 so a future change
that reintroduces 0666 fails the smoke test.
2026-05-06 11:47:38 +02:00
oech3andDaniel Hofstetter 529467d8e5 reduce usage of nix::unistd::geteuid 2026-05-06 11:41:38 +02:00
Sylvestre LedruandGitHub 20f7af8732 stat: warn once when QUOTING_STYLE env has an unknown value (#12136)
* stat: warn once when QUOTING_STYLE env has an unknown value

* Add spell-checker directive to test_stat.rs
2026-05-06 10:16:13 +02:00
oech3andDaniel Hofstetter aeaf810eb5 test_tail.rs: increase delay 2026-05-06 08:35:00 +02:00
Daniel HofstetterandDorian Péron adce17fa26 ls: use lines() instead of split('\n') in test 2026-05-05 15:50:30 +02:00
Guillem L. JaraandDaniel Hofstetter f7ba1f9b07 chore(ls): test for sorting stability 2026-05-05 11:22:45 +02:00
Sylvestre LedruandGitHub 4a69cf0c5e tr: drop '[:...:]' wrapper from invalid character class error (#12122) 2026-05-04 09:54:56 +02:00
Sylvestre LedruandGitHub 163103355a head: strip os error suffix from stdout write error message (#12121) 2026-05-04 09:38:54 +02:00
Sylvestre LedruandGitHub b2c4e0c125 factor: emit GNU 9.11 'is not a valid positive integer' for stdin input (#12137)
* factor: emit GNU's 'X is not a valid positive integer' wording

GNU's factor.c routes both stdin and command-line input through the same
print_factors() and reports invalid input as
  factor: 'X' is not a valid positive integer
Match that wording exactly so the new GNU 9.11 'nul4' test passes and
the 'cont' test no longer needs the warning/invalid-digit hunk in
tests_factor_factor.pl.patch.

* Add 'cmdline' to spell-checker ignore list
2026-05-04 09:31:59 +02:00
Guillem L. JaraandDaniel Hofstetter f774940451 fix(ls): place dot dirs on top in version sorting
Also fixes the fact that version sorting had incorrect edge cases due to wrong name passing.
2026-05-01 15:09:49 +02:00
pocopepeandDaniel Hofstetter 375fc3cd48 numfmt: reject %f values too large to format exactly 2026-05-01 09:40:58 +02:00
oech3andDorian Péron 4620c2f3b6 yes: use tee syscall as fast-path 2026-04-30 14:45:28 +02:00
b3d8706a2c sort: fix inconsistent sort ordering under i18n-collator with equal sorting keys (#12013)
* sort: Fix inconsistent sort orderg under i18n-collator with equal sorting keys.

* Test cases for fix #11980

* Simplyfing fix for #11980

* Fix clippy lint and rename test files.

* Remove old test files

* Update tests/by-util/test_sort.rs

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* Update tests/by-util/test_sort.rs

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* Removing redundant test and swapping default order for sort to match sort's ordering.

* Comment for clarification.

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
2026-04-30 10:33:48 +02:00
oech3andDaniel Hofstetter dd72eca93c tty: Build for Windows 2026-04-29 11:03:10 +02:00
oech3andDaniel Hofstetter 5aade310be test_test.rs: remove unsafe 2026-04-28 14:24:49 +02:00
oech3andGitHub ec72d08bf1 test_nohup.rs: remove unsafe (#12052) 2026-04-28 10:52:33 +02:00
xtqqczzeandDaniel Hofstetter c2acff22ee clippy: fix items_after_statements lint
https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements
2026-04-28 09:37:21 +02:00