Repository navigation
coreutils: restrict prefix matching so names like pwd-symlink do not false-match (#16848) - #16975
yunusarda-sudo wants to merge 4 commits 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.
Keep restricted prefix matching as the uutils#16848 fix, but call utility_from_symlink only on linux-gnu after name matching fails so usual invocations do not pay readlink. Drop the multi-hop walker (one hop is enough) and switch the regression test to true.
Fold exact matches into the prefix filter and keep uls/ucat working.
Leave hardlink/symlink resolution to uutils#16981 and keep a regression test that true-symlink does not false-match link.
66699a9 to
87092c9
Compare
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