Repository navigation
fix(builtins): literal-file existence gate on the /bin|/usr/bin RedirectToBuiltin faces (#2093) - #2147
Merged
Conversation
…ectToBuiltin faces (#2093) Root cause: the six claimed slash spellings (/bin, /usr/bin of echo/printf/pwd) answered BUILTIN semantics unconditionally, with no check on the literal file the spelling names. GNU spec: findcmd.c search_for_command treats a slash-bearing word as an absolute program (findcmd.c:383-385, absolute_program => savestring(pathname)) and execute_cmd.c shell_execve execve's it verbatim — a real file at that path answers with its own semantics (--help/--version banner, no xpg_echo sensitivity, physical pwd). Rubash faces: external_inner.rs handle_external_shortcuts (echo arm) and external_file_builtins.rs handle_external_file_builtins (pwd/printf arms). Fix (the issue's adjudicated 候选修法): path.rs literal_executable_file() probes exactly the literal resolution find_user_command_uncached's slash branch performs first (anchor_at_session_cwd over shell_path_to_windows, then executable_candidate) — deliberately WITHOUT that branch's Windows basename-PATH fallbacks, so a PATH-resolvable echo with no literal /bin/echo file keeps the redirect (Windows no-/bin default unchanged: byte-identical in the A/B closed-root matrix). Both faces decline to the real exec path when the gate opens; the documented gating asymmetry is preserved (printf/pwd ride the external_file_builtins host flag, echo does not — the gate alone decides on the echo face). Contract text updated in command_registry.rs SlashKind::RedirectToBuiltin and docs/builtins.md §4.3. Tests: tests/issue2093_literal_file_redirect_regressions.rs — Windows pins drive the gate through __RUBASH_SHELL_ROOT (empty root = redirect stays byte-for-byte; root with literal .bat files = the files answer; host-flag matrix pins the asymmetry), unix pins compare rubash's answer with a direct spawn of the same literal file (echo --version, xpg_echo, printf --version, pwd physical default through a symlink tail). Results: 3/3 Windows, 4/4 WSL GNU-bash-5.3.20 Linux. GNU oracle probes reproduce the issue's three divergence families; A/B vs pristine d5c172a: closed-root matrix identical, Linux suite slice (comsub2/varenv/alias/ exportfunc/intl/trap drivers) pristine-vs-fixed identical modulo the binary's own diagnostic path. No regression in the Windows battery (lib 1063 pass; every failing target, and the issue1708 compile break, fails identically on pristine master). fmt disclosure: hook `cargo fmt` fails with os error 206 (filename or extension too long, crate-wide scan over the 862-file tests/ dir) — same precedent as prior hooks; explicit per-file rustfmt run instead (rustfmt --check clean on all five touched files).
Member
Author
|
主会话审阅记录(2026-10-30):本 PR 其余 CI 全绿,唯 Windows「GNU regression goldens and canaries」的 regression 套件 1 红—— 该钉不在本 PR 的六拼写面内(cat 非 echo/printf/pwd),但本 PR 动了 path.rs 的解析路径,且 fifo 的 Broken pipe 形状本身也有时序 flake 的前科,单次数据分不清「路径改动连带」还是「fifo 竞态」。主会话已触发 failed-jobs 重跑做二分:重跑转绿 = flake,按用户裁定(合同批破例进 1.5.0、审过就合)直接合;同钉再红 = 视为本 PR 连带,请作者侧定位(优先看 path.rs 解析变化对该钉 marker 路径的影响),主会话不自行改作者分支。 |
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.
Closes #2093.
Root cause (GNU C source is the specification)
The registry's
SlashKind::RedirectToBuiltinclaims six exact spellings (/bin,/usr/bin×echo/printf/pwd). Both claim faces answered BUILTIN semantics unconditionally — no check on the literal file the spelling names:src/executor/external_inner.rshandle_external_shortcuts(echo arm — the external-shortcut face, not host-flag gated)src/executor/external_file_builtins.rshandle_external_file_builtins(pwd/printf arms — the external-file-builtins face, host-flag gated)GNU spec:
findcmd.csearch_for_commandtreats a slash-bearing word as an absolute program (findcmd.c:383-385,absolute_program => savestring(pathname)), andexecute_cmd.cshell_execveexecve's it verbatim — so on any host where the literal file exists, the file answers (--help/--versionbanner, noxpg_echo, physical-pwd default). Exactly the three divergence families measured in the issue against GNU bash 5.3.20.Fix (the issue's adjudicated 候选修法 — 存在性门)
New
path.rsgateliteral_executable_file(): probes exactly the literal resolutionfind_user_command_uncached's slash branch performs first (anchor_at_session_cwdovershell_path_to_windows, thenexecutable_candidate) — deliberately without that branch's Windows basename-PATH fallbacks, so a PATH-resolvableechowith no literal/bin/echofile keeps the redirect.external_file_builtinshost flag, echo does not; the gate alone decides on the echo face.Contract text updated in
command_registry.rsSlashKind::RedirectToBuiltinanddocs/builtins.md§4.3.Verification
tests/issue2093_literal_file_redirect_regressions.rs— Windows pins drive the gate through__RUBASH_SHELL_ROOT(empty root → redirect stays byte-for-byte; root with literal.batfiles → the files answer; host-flag matrix pins the asymmetry). Unix pins compare rubash's answer with a direct spawn of the same literal file (the file is its own oracle):echo --version,xpg_echoinsensitivity,printf --version,pwdphysical default through a symlink tail.a\tbunderxpg_echo, physical pwd under symlinked$PWD).d5c172ae: closed-root matrix byte-identical; open-root matrix flips exactly the six-spelling faces to file semantics. Linux suite slice (comsub2/varenv/alias/exportfunc/intl/trap drivers, the files touching the six spellings): pristine-vs-fixed identical modulo the binary's own diagnostic path.fmt disclosure
cargo fmtfails with os error 206 (filename or extension too long — crate-wide scan over the 862-filetests/dir), same precedent as prior hooks; explicit per-filerustfmtrun instead (rustfmt --checkclean on all five touched files). Committed with--no-verifyfor that reason only.