Repository navigation
fix(realpath): reject non-directory path components and forcing them to ENOTDIR - #16153
Martell0x1 wants to merge 9 commits into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
Merging this PR will degrade performance by 0.56%2 warnings, 1 note
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
2f1fa3d to
3cc5e18
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
@codspeedbot explain why performance improved |
| OwningComponent::CurDir => {} | ||
| OwningComponent::ParentDir => { | ||
| // checking for current component | ||
| if !result.as_os_str().is_empty() { |
There was a problem hiding this comment.
this also runs with MissingHandling::Missing, so realpath -m missing/.. and -m file/.. fail now, GNU accepts both
please skip the check in that mode and add a -m test
There was a problem hiding this comment.
ignored the check for MissingHandler::Missing
| Ok(meta) if meta.is_dir() => {} | ||
| Ok(_) => { | ||
| return Err(Error::new(ErrorKind::NotADirectory, "Not a directory")); | ||
| } |
There was a problem hiding this comment.
why rebuild a NotFound error? Err(e) => return Err(e) is enough
| OwningComponent::CurDir => {} | ||
| OwningComponent::ParentDir => { | ||
| // checking for current component | ||
| if !result.as_os_str().is_empty() { |
There was a problem hiding this comment.
could you please reuse ensure_is_directory(&result)? here? it already gives ENOTDIR, without the hardcoded strings
|
|
||
| // spell-checker:ignore nusr | ||
|
|
||
| use uucore::util_name; |
There was a problem hiding this comment.
util_name is already imported from uutests, does this compile?
There was a problem hiding this comment.
actually it did , i guess as rust allows importing the same macro's name but from different paths
| .ucmd() | ||
| .arg("regular_file/..") | ||
| .fails() | ||
| .code_is(1) |
There was a problem hiding this comment.
the issue also mentions -L, -e and readlink -f, please add tests for them
-L still goes through normalize_path, so it isn't fixed yet
There was a problem hiding this comment.
yes i totaly forgot to add Logical path support .
|
|
||
| at.mkdir("directory"); | ||
|
|
||
| scene.ucmd().arg("directory/..").succeeds(); |
There was a problem hiding this comment.
please check the stdout too, not only the exit code
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
e7c8a6b to
8fbaeb1
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
thanks for looking into this! |
| } | ||
| } | ||
|
|
||
| fn validate_parent_compoenent(path: &Path) -> IOResult<()> { |
There was a problem hiding this comment.
typo: compoenent
and could you please add a one-line doc? the name doesn't say it checks for ..
| .arg("regular_file/..") | ||
| .fails() | ||
| .code_is(1) | ||
| .stderr_contains("Not a directory"); |
There was a problem hiding this comment.
please use NOT_A_DIRECTORY, it is already defined at the top of the file for windows
| .ucmd() | ||
| .arg("directory/..") | ||
| .succeeds() | ||
| .stdout_is(format!("{}\n", at.root_dir_resolved())); |
There was a problem hiding this comment.
the other tests using root_dir_resolved() have #[cfg_attr(wasi_runner, ignore = ...)], these ones probably need it too
| .arg("regular_file/..") | ||
| .fails() | ||
| .code_is(1) | ||
| .stderr_contains("Not a directory"); |
There was a problem hiding this comment.
this fails on windows, the message there is "The directory name is invalid."
please use a NOT_A_DIRECTORY const like in test_readlink.rs (same for the -L and -e tests)
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
97f51ff to
1a8c9ac
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
@sylvestre
Thanks for pointing these out! |
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
| #[cfg(windows)] | ||
| use std::os::windows::io::AsRawHandle; | ||
| use std::path::{Component, MAIN_SEPARATOR, Path, PathBuf}; | ||
| use std::path::{Component, Path, PathBuf, MAIN_SEPARATOR}; |
There was a problem hiding this comment.
the last commit reformatted unrelated code with an old rustfmt style (imports, the 's'/'S' lines below)
please revert those hunks, the workspace is edition 2024, cargo fmt --all will put them back
| } | ||
| OwningComponent::CurDir => {} | ||
| OwningComponent::ParentDir => { | ||
| // checking for current component |
There was a problem hiding this comment.
this comment doesn't add anything, please remove it
| OwningComponent::CurDir => {} | ||
| OwningComponent::ParentDir => { | ||
| // checking for current component | ||
| if !result.as_os_str().is_empty() && miss_mode != MissingHandling::Missing { |
There was a problem hiding this comment.
this also runs with -s (ResolveMode::None), so realpath -s file/.. and -s missing/.. change too
could you please check what GNU does and add a -s test?
| #[cfg_attr(wasi_runner, ignore = "WASI sandbox: host paths not visible")] | ||
| fn test_realpath_directory_followed_by_parent_dir_missing_mode() { | ||
| let scene = TestScenario::new(util_name!()); | ||
| let at = &scene.fixtures; |
There was a problem hiding this comment.
please also test -m regular_file/.., it should succeed too
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
@sylvestre I'm still relatively new to open source, so I'm learning a lot through reviews like yours. I really appreciate you taking the time to point out these details and help me improve. |
…ng mode and fixed tests
bc37014 to
ebdec2c
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
|
Hi @sylvestre |
|
Hi @sylvestre , Any Updates on this PR ? |
Problem
uutils
realpathincorrectly accepts paths containing a regular file followed by...For example,
/tmp/example/file/..succeeds in uutils, whereas GNUrealpathfails withENOTDIR(Not a directory).The implementation removes the preceding component when encountering
ParentDirwithout verifying that the component is a directory.Root Cause
In
src/uucore/src/lib/features/fs.rs, theParentDirbranch performs:This removes the preceding component without validating whether it can be traversed as a directory.
Fix
Validate path components before resolving
ParentDir, rejecting non-directory and nonexistent intermediate components where required by the selected resolution mode.Tests
cargo test --no-default-features --features realpathRequires #16161
Closes #16117