Repository navigation
coreutils: restrict prefix matching so names like pwd-symlink do not false-match (#16848) - #16975
yunusarda-sudo wants to merge 1 commit into
Conversation
|
Sorry. I don't agree with it. This is downstreams packaging issue and resoving always means we introduce an overhead of readlink at most usual usecases. I was considering to submit a PR to avoid that overhead when binaries are installed under |
| return utils.keys().find(|&&k| k == name).copied(); | ||
| } | ||
| // Prefix match: e.g. "uu-cat", "coreutils-cat", "x86_64-linux-gnu-cat", "gcat". | ||
| // Must be separated by a delimiter ('-', '_', '.') or the standard 'g' (GNU) prefix. |
There was a problem hiding this comment.
Why do we need those limitations?! Thye don't have anything special.
There was a problem hiding this comment.
Without them, pwd-symlink/true-symlink matches link.
There was a problem hiding this comment.
This is downstream's packaging issue. We should not have such hack.
There was a problem hiding this comment.
Also note that people can create pwdsymlink too.
| let name = validation::name(&target)?; | ||
| matched_utility(name, utils) | ||
| let mut current = binary.to_path_buf(); | ||
| for _ in 0..40 { |
There was a problem hiding this comment.
Please don't do that. There is no actual usecase. We don't need to increase complexity for downstream's packaging issue. Or use /proc/self/exe.
There was a problem hiding this comment.
This issue is existing on main too, but readlink causes race condition.
There was a problem hiding this comment.
Dropped the loop; a single read_link is enough here. The remaining race is pre-existing on main — happy to follow up separately.
There was a problem hiding this comment.
There is no safe-traversal way to support symlink install. Thus, we must restrict this extension to hardlink installs i.e we must lost current extension.
Fake /proc is theorically possible, but I'm not sure if it is worth to doubt it.
There was a problem hiding this comment.
Agreed, dropped symlink resolution; this PR now only tightens prefix matching, complementary to #16981.
There was a problem hiding this comment.
Please just close this PR. Restricting prefix matching does not do anything.
There was a problem hiding this comment.
pwd-symlink "should" match with link. This is definition of our our extension.
pwd-sym is a valid prefix. The linked issue is really invalid.
| if let Some(util) = matched_utility(name, utils) { | ||
| return Some(util); | ||
| } | ||
| if name.ends_with("utils") || name.ends_with("box") { |
There was a problem hiding this comment.
box is a hack existing just for running busybox testsuite on the CI. We don't need to care about it at here.
There was a problem hiding this comment.
Removed with the walker.
| // binary name ends with util name? | ||
| let is_coreutils = binary_as_util.ends_with("utils"); | ||
| let util_name = if let Some(util) = matched_utility(binary_as_util, &utils) { | ||
| let util_name = if let Some(util) = utility_from_symlink(&binary, &utils) { |
There was a problem hiding this comment.
This introduces an overhead of readlink(2) call to the all usual usecases.
There was a problem hiding this comment.
Moved it back to the linux+gnu fallback after name matching, so usual cases no longer pay readlink.
| } | ||
|
|
||
| #[test] | ||
| #[cfg(all(unix, feature = "pwd"))] |
There was a problem hiding this comment.
Depending on pwd is highcost. true or echo is enough.
There was a problem hiding this comment.
Switched the test to true.
| // todo: Remove support of "*box" from binary | ||
| uucore::set_utility_is_second_arg(); | ||
| args.next() | ||
| } else if cfg!(all(target_os = "linux", target_env = "gnu")) |
There was a problem hiding this comment.
Removing this cfg does not help other platforms because full path is not used at other platforms.
Supporting it by parsing PATH causes race condition.
There was a problem hiding this comment.
Restored the cfg.
084de3b to
e2f2370
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
I opened #16981 instead. |
| if let Some(prefix) = name.strip_suffix(util) { | ||
| prefix.ends_with('-') | ||
| || prefix.ends_with('_') | ||
| || prefix.ends_with('.') |
There was a problem hiding this comment.
this breaks PROG_PREFIX without a separator, e.g. homebrew installs uls, ucat (prefix u)
they would no longer dispatch, please add a test for such a name
There was a problem hiding this comment.
In any case, this is regression and pwdsymlink, or simply link -> pwd is not supported.
There was a problem hiding this comment.
Restored single-letter prefixes (uls/ucat) and added a test.
| } | ||
| // Prefer stty over tty, and never treat *utils as ls. | ||
| // Exact match has highest precedence. | ||
| if utils.contains_key(name) { |
There was a problem hiding this comment.
could be folded into the filter with prefix.is_empty(), no?
and ends_with(['-', '_', '.']) would be shorter
There was a problem hiding this comment.
Folded the exact match into the filter as suggested.
e2f2370 to
5b8bb59
Compare
|
#16981 covers |
|
This ofcause depends on hardlink install. But the limitation is no probrem because there is not compatibility issue with GNU's multi-call coreutils. Mimicing individual binaries is just a best effort. Downstream just need to choice installing binaries as hardlinks (which is GNUmakefile's default). |
| // Prefer stty over tty, and never treat *utils as ls. | ||
| // Exact match, delimited prefix (uu-cat, coreutils-cat, x86_64-linux-gnu-cat), | ||
| // or a single-letter PROG_PREFIX without a separator (uls, ucat, gcat). | ||
| // Rejects false suffix matches such as pwd-symlink -> link. |
There was a problem hiding this comment.
Do you think that pwd-link and pwdlink should be pwd? I don't think so.
There is no way to make every one happy at here. Please close this PR.
66699a9 to
87092c9
Compare
This comment was marked as resolved.
This comment was marked as resolved.
87092c9 to
5965cec
Compare
|
We probably should stop resolving prefix at "runtime" to avoid unnecessary confusion and overhead. We should support
|
| .filter(|&&util| { | ||
| name.strip_suffix(util).is_some_and(|prefix| { | ||
| prefix.is_empty() | ||
| || prefix.ends_with(['-', '_', '.']) |
There was a problem hiding this comment.
. breaks file_stem(). Also, this approach does not cover any separator you don't know e.g. emoji.
There was a problem hiding this comment.
Good catch on . (file_stem() never yields it) — dropped in a01ae78. Other separators are intentionally not covered; the build.rs-only PROG_PREFIX direction would also break uls/ucat that sylvestre asked to keep, so I will leave that call to the maintainers.
There was a problem hiding this comment.
My point at here is specializing some specific chara\cters only is nonsense. People can consider any character e.g . w. In the case, pwdsymlink is separated to p and dsymlink and it should match with link.
5965cec to
a01ae78
Compare
|
Until you provide an answer for |
|
Already a single commit (a01ae78). |
|
|
a01ae78 to
0d1f5b4
Compare
|
Updated extensions.md; the supported separators are listed there explicitly. |
|
I really hope that you close this PR whthout waiting maintainers review... |
|
|
||
| Our `coreutils` calls utility by `coreutils utility-name` and has `--list` to run against busybox test suite. | ||
| Our `coreutils` is called as `utility-name` if its binary name ends with `utility-name` to support prefixed names. | ||
| Our `coreutils` is selected as `utility-name` when the binary name is exactly that utility, when it has a prefix ending in `-` or `_` (e.g. `uu-cat`, `coreutils-cat`, `x86_64-linux-gnu-cat`), or when a single-letter prefix has no separator (e.g. `uls`, `ucat`, `gcat`). Other separators are intentionally not supported. |
There was a problem hiding this comment.
Why single letter only? Someone might use uucat, uutilscat, rustcat. Then you need to handle many confusing 2 letter case e.g. lscat.
When the multicall binary is invoked as a name such as
pwd-symlink,matched_utilitypreviously performed unconstrained suffix matching (name.ends_with(util)). Becausepwd-symlinkends withlink,uu_linkwas dispatched, causing glibc'stst-spawn-chdirtest to fail on Ubuntu (Launchpad #2161727).This change tightens
matched_utilityto accept:-or_(e.g.uu-cat,coreutils-cat,x86_64-linux-gnu-cat),uls,ucat,gcat).Symlink and hardlink resolution is left unchanged; that is complementary to #16981.
Fixes #16848