fix(install): zero umask at startup so ancestor dirs are created at exact 0755#12715
Open
abendrothj wants to merge 4 commits into
Open
fix(install): zero umask at startup so ancestor dirs are created at exact 0755#12715abendrothj wants to merge 4 commits into
abendrothj wants to merge 4 commits into
Conversation
…xact 0755 GNU install calls umask(0) early in main() so that ancestor directories created by -D/-d always get exactly DEFAULT_MODE (0755) regardless of the caller's umask. Our implementation passed DEFAULT_MODE to mkdirat / fs::create_dir_all without zeroing umask first, so restrictive umasks (e.g. 0027, 0077, 0111) produced wrong ancestor modes. Changes: - Add zero_umask() to uucore::mode using the existing rustix dependency - Call it at the top of install's uumain (unix only) - Fix the -d code path to use DirBuilder::mode(DEFAULT_MODE) instead of fs::create_dir_all, which defaults to 0777 and would create 0777 ancestors with umask now zeroed - Replace the broken probe-based assertions in two tests with direct assert_eq!(0o40_755) checks, matching the GNU-guaranteed value Fixes uutils#12714 Related: uutils#11363, uutils#12713
|
GNU testsuite comparison: |
Contributor
Author
|
CI is clean except for one failure: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #12714
Related: #11363, #12713
Root cause
GNU
installcallsumask(0)early inmain()so that ancestor directories created by-D/-dalways get exactlyDEFAULT_MODE(0755) regardless of the caller's umask. uutils passedDEFAULT_MODEtomkdirat/fs::create_dir_allwithout zeroing umask first, so restrictive umasks (e.g.0027,0077,0111) produced wrong ancestor modes.The existing tests masked this because they used a
mkdir-based probe to capture the expected permissions. With umask0002the probe yields0775while install produces0755— causing a spurious test failure that looked like a bug in the tests, not the implementation.Changes
src/uucore/src/lib/features/mode.rszero_umask()using the existingrustixdependency — sets process umask to 0 and returns the old valuesrc/uu/install/src/install.rsuucore::mode::zero_umask()at the top ofuumain(unix only), matching GNU's behaviour-dcode path (directory()) to useDirBuilder::mode(DEFAULT_MODE)instead offs::create_dir_all, which defaults to mode0777and would create0777ancestors now that the umask is zeroedtests/by-util/test_install.rstest_install_ancestors_mode_directoriesandtest_install_ancestors_mode_directories_with_filewithassert_eq!(0o40_755_u32, ...), which is the value GNU actually guaranteesTest plan
cargo test --features unix test_install— all 92 install tests pass0755