Commit Graph
76 Commits
Author SHA1 Message Date
0c5f76c501 parse_numeric: print mode in octal when the mode is too large (#10208)
This was caught when testing chmod inside of Redox OS.
Previously, doing `chmod 10777 file` will cause an error stating that
"mode is too large (4607 > 7777", which is both incorrect and contains
a missing parenthesis. We now print the large octal value in terms of
octal.

Co-authored-by: Connor-GH <connor-gh@outlook.com>
2026-02-03 09:43:48 -05:00
30239e69a3 feat: Expand safe directory traversal to all Unix platforms and fix related type conversions. (#9792)
---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2026-01-09 08:22:56 +01:00
cerdelenandGitHub 413055b378 Chmod preserve root (#10033)
* chmod: Fix --preserve-root not being bypassed by path that resolves to root

* chmod: Regression tests for --preserve-root not being bypassed by path that resolves to root
2026-01-07 10:49:54 +01:00
cerdelenandGitHub d28cb30c63 Merge pull request #9990 from cerdelen/chmod_recursive_hyper_nested_dirs
Chmod recursive hyper nested dirs
2026-01-03 11:40:51 +01:00
abd581f62e chmod: fix error handling if multiple files are handled (#9793)
* chmod: fix error handling if multiple files are handled

* chmod: add regression test for correct exit codes

* chmod: fix test expected error msg

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2026-01-01 11:41:05 +01:00
Sylvestre LedruandGitHub 1c358695ec Merge branch 'main' into lossy-string-cleanup 2025-12-26 23:17:23 +01:00
mattsuandGitHub 13ea1fc1d1 chmod:fix safe traversal/access (#9554)
* feat(chmod): use dirfd for recursive subdirectory traversal

- Update chmod recursive logic to use directory file descriptors instead of full paths for subdirectories
- Improves performance, avoids path length issues, and ensures dirfd-relative openat calls
- Add test to verify strace output shows no AT_FDCWD with multi-component paths

* test(chmod): add spell-check ignore for dirfd, subdirs, openat, FDCWD

Added a spell-checker ignore directive in the chmod test file to suppress false positives for legitimate technical terms used in Unix API calls.

* test(chmod): enforce strace requirement in recursive test, fail fast instead of skip

Previously, the test_chmod_recursive_uses_dirfd_for_subdirs test skipped gracefully if strace
was unavailable, without failing. This change enforces the strace dependency by failing the
test immediately if strace is not installed or runnable, ensuring the test runs reliably
in environments where it is expected to pass, and preventing silent skips.

* ci: install strace in Ubuntu CI jobs for debugging system calls

Add installation of strace tool on Ubuntu runners in both individual build/test and feature build/test jobs. This enables tracing system calls during execution, aiding in debugging and performance analysis within the CI/CD pipeline. Updated existing apt-get commands and added conditional steps for Linux-only installations.

* ci: Add strace installation to Ubuntu-based CI workflows

Install strace on ubuntu-latest runners across multiple jobs to enable system call tracing for testing purposes, ensuring compatibility with tests that require this debugging tool. This includes updating package lists in existing installation steps.

* chore(build): install strace and prevent apt prompts in Cross.toml pre-build

Modified the pre-build command to install strace utility for debugging and added -y flag to apt-get install to skip prompts, ensuring non-interactive builds.

* feat(build): support Alpine-based cross images in pre-build

Detect package manager (apt vs apk) to install tzdata and strace
in both Debian/Ubuntu and Alpine *-musl targets. Added fallback
warning for unsupported managers. This ensures strace is available
for targets using Alpine, which doesn't have apt-get.

* refactor(build): improve pre-build script readability by using multi-line strings

Replace escaped multi-line string with triple-quoted string for better readability in Cross.toml.

* feat(ci): install strace in WSL2 GitHub Actions workflow

Install strace utility in the WSL2 environment to support tracing system calls during testing. Minor update to Cross.toml spell-checker ignore list for consistency with change.

* ci(wsl2): install strace as root with non-interactive apt-get

Updated the WSL2 workflow step to use root shell (wsl-bash-root) for installing strace, removing sudo calls and adding DEBIAN_FRONTEND=noninteractive to prevent prompts. This improves CI reliability by ensuring direct root access and automated, interrupt-free package installation.

* ci: Move strace installation to user shell and update spell ignore

Fix WSL2 GitHub Actions workflow by installing strace as the user instead of root for better permission handling, and add "noninteractive" to the spell-checker ignore comment for consistency with the new apt-get command. This ensures the tool is available in the testing environment without unnecessary privilege escalation.

* chore: ci: remove unused strace installation from CI workflows

Remove strace package installation from multiple GitHub Actions workflow files (CICD.yml, l10n.yml, wsl2.yml). Strace was historically installed in Ubuntu jobs for debugging system calls, but it's no longer required for the tests and builds, reducing CI setup time and dependencies.

* ci: add strace installation and fix spell-checker comments in CI files

- Install strace package in CICD workflow to support safe traversal verification for utilities like rm, chmod, chown, chgrp, mv, and du, enabling syscall tracing for testing.
- Clean up spell-checker ignore comments in wsl2.yml and Cross.toml by removing misplaced flags.第二个测试产品**ci: add strace installation and fix spell-checker comments in CI files**

- Install strace package in CICD workflow to support safe traversal verification for utilities like rm, chmod, chown, chgrp, mv, and du, enabling syscall tracing for testing.
- Clean up spell-checker ignore comments in wsl2.yml and Cross.toml by removing misplaced flags.

* test: add regression guard for recursive chmod dirfd-relative traversal

Add a check in check-safe-traversal.sh to ensure recursive chmod operations use dirfd-relative openat calls instead of AT_FDCWD with multi-component paths, preventing potential race conditions. Ignore the corresponding Rust test as it is now covered by this shell script guard.
2025-12-05 19:50:34 +01:00
Jan Verbeek 3e1e61782e chmod: Use full "permission denied" error message
Part of the error message was left out due to a misreading of
tests/chmod/no-x's output. It filters out this part for the sake of
normalization between different tools.
2025-11-19 22:10:23 +01:00
Jan Verbeek e4024045a0 Do not use .display()/.to_string_lossy() unnecessarily
This comes up a lot for quoted strings in messages: OS strings can be
quoted directly and this prevents information loss.

This commit removes ~60% of the calls to these methods (modulo
tests). Some of the remaining calls are benign, for example because
they convert solely to check for the presence of ASCII
characters. Others are nontrivial to improve.
2025-11-19 20:48:24 +01:00
4a92c9b638 safe traversal: adjust chmod & chgrp to use it (#8632)
* chown: implement safe traversal

* uucore/safe_traversal: add secure chmod functions

* safe traversal: adjust chmod & chgrp to use it

* chmod dedup some code

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

* address review comments

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
2025-09-23 09:28:15 +02:00
Sylvestre LedruandDaniel Hofstetter 23f3551e1c clap/locale: fix the colors for all programs (Closes: #8501)
Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
2025-09-05 08:25:59 +02:00
Sylvestre Ledru 218baa3f88 chmod: make a test environment-agnostic
run ssh, it might break with:

---- test_chmod::test_chmod_umask_expected stdout ----

thread 'test_chmod::test_chmod_umask_expected' panicked at tests/by-util/test_chmod.rs:240:5:
assertion `left == right` failed: Unexpected umask value: expected 022 (octal), but got 002. Please adjust the test environment.
  left: 2
 right: 18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2025-08-29 22:53:09 +02:00
Sylvestre Ledru c366551b02 tests: add test for chmod with non-UTF-8 filenames 2025-08-14 10:52:24 +02:00
Sylvestre Ledru 21c8e42c8f chmod: fix recursive symlink handling for -H/-L/-P flags (Closes: #8422) 2025-08-09 17:34:52 +02:00
Yuri Astrakhan a27880e8a3 chore: use assert_eq! and assert_ne! instead of assert!
Makes intent clearer, and if something fails, prints the values that caused the failure as part of the panic message.
2025-04-08 13:25:41 -04:00
Yuri Astrakhan 982805d3cd chore: manual inline formatting
Minor manual cleanup - inlined many format args.  This makes the code a bit more readable, and helps spot a few inefficiencies and possible bugs.  Note that `&foo` in a `format!` parameter results in a 6% extra performance cost, and does not get inlined by the compiler (yet).
2025-04-08 00:23:21 -04:00
b7bf8c9467 chmod: Correct chmod -R on dangling symlink and tests (#7618)
* Correct chmod -R on dangling symlink and tests

* Add tests of arg-level symlink to chmod

* Add tests of all symlink flag combos on chmod dangling

* Fix no traverse on dangling symlink

* Add chmod recursive tests of default symlink method

* Add default chmod -H flag tests

* Set chmod default traversal method correctly to -H

* Fix arg symlink chmod case

* Remove extra chmod -H testing

---------

Co-authored-by: Clifford Ressel <EMAIL@gmail.com>
2025-04-07 16:18:00 +02:00
Sylvestre Ledru a0179ea239 uutests: adjust the tests to use them 2025-03-28 21:40:31 +01:00
Sylvestre Ledru a85539f530 Run cargo fmt on the tree 2025-03-24 21:33:12 +01:00
Daniel Hofstetter df4dfea852 tests: replace run() with succeeds() or fails() 2025-03-09 16:53:56 +01:00
Sylvestre Ledru 18cb7dcf9e Use the new function fails_with_code
Done with
```
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.no_stdout\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2)\n\1.no_stdout();/gs' *rs
$ sed -i -e "s|.fails()(.*).code_is(|.fails_with_code(|g" *rs
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2);/gs' *rs
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)(.*?)[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\3)\2;/gs' *rs
...
```
2025-03-01 17:26:20 +01:00
Sylvestre Ledru 6457836f33 chmod: Remove misleading comments 2025-01-11 16:07:07 +01:00
Sylvestre Ledru 78b09f400b chmod: merge some tests into one 2025-01-11 12:48:30 +01:00
Sylvestre Ledru b0126fdc68 chmod: Implement --dereference, -L, -H, etc
Should fix tests/chmod/symlinks.sh
2025-01-11 12:48:30 +01:00
Sylvestre Ledru c47ead3639 chmod: split a test into two as they are testing different things 2025-01-11 12:48:30 +01:00