Repository navigation
fix(executor): hash consult returns the fs path of the served spelling - #3847
Merged
Merged
Conversation
…g (Refs #3845) find_user_command's hash-mirror consult handed phash_search's stored string to callers verbatim as a PathBuf. The hash table keeps the shell-domain display spelling (/d/..., ./elem/name) for `hash -t` fidelity; on unix that string already is the filesystem path execute_cmd.c:6133 shell_execve execve()s, but on Windows it is not spawnable — Command::new ENOENTs and the diagnostic escapes to the shell's stderr, e.g. `cat cap4 | wc -c` inside a command substitution after any earlier `cat` run recorded the entry (golden issue1230). Introduce: #3554 (46bb796) replaced `return Some(path.clone())` — the mirror's fs path — with the verbatim served spelling for the CHKDOT/RELPATH re-validation arm. #3631 is innocent: the parent tree (9148457) reproduces the leak identically. Return shell_path_to_windows(served) instead — the same funnel record_command_resolution used to build the mirror. It is the identity on unix, maps /d/... to D:\..., and keeps ./elem/name relative so the post-cd ENOENT re-resolution of rubash#2696 is preserved. The checkhash probe now stats the real file too. Pin: executor::path::tests:: hash_consult_returns_spawnable_fs_path_for_display_spelling (red before, green after). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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 #3845
Root cause
golden_issue1230_exec_redirect_undoleaked.../cat.exe: No such file or directoryto stderr from fixture line 9 (echo "cap4 size: $(cat cap4 | wc -c)").find_user_command's hash-mirror consult (src/executor/path.rs) returnedphash_search's stored string verbatim as the execPathBuf. The hash table stores the shell-domain display spelling (/d/...,./elem/name) forhash -tfidelity. On unix that string already is the filesystem pathexecute_cmd.c:6133shell_execvehands toexecve; on Windows it is not spawnable, soCommand::newENOENTs and the spawn diagnostic reaches the shell's stderr (inside a comsub, fd 2 is inherited —subst.ccommand substitution does not capture stderr, so a real spawn failure does print there; the bug is that the spawn fails at all).Sequence in the fixture: line 6
cat cap2resolvescatand records/d/Git/usr/bin/cat.exein the hash table + fs-path mirror; line 9's comsub pipeline resolvescatthrough the mirror consult, gets the/d/spelling back, and the concurrent pipeline-stage spawn fails ENOENT.Was #3631 the cause? — No.
Bisected locally with script-file reproduction (
tests/regression/fixtures/issue1230-exec-redirect-undo.sh, PATHC:\Windows\System32;D:\Git\usr\binmirroring the harness shape):9f2cf15f3(fix(hash): re-validate relative hash entries on every read (Refs #3359) #3554's parent): green — stdout byte-identical to GNU, stderr empty.914845727(fix(executor): resolve sequential 2>&1 against the dup-time snapshot (Refs #3403) #3631's direct parent, post-fix(hash): re-validate relative hash entries on every read (Refs #3359) #3554): red — same extra stderr line.a41909d3e(master tip pre-fix): red.The true introducer is #3554 (
46bb796b2), whose diff replacedreturn Some(path.clone())(the mirror's fs path) withPathBuf::from(served)for the CHKDOT/RELPATH re-validation arm (rubash#3359/#3551). #3631's sequential-2>&1fold never runs for this shape — the comsub pipeline takes the concurrent external path.Invariant restored
find_user_commandreturns the filesystem path of the spelling GNU would exec, not the spelling itself. The fix returnsshell_path_to_windows(served, env_vars)— the same funnelrecord_command_resolutionused to build the mirror:/d/Git/usr/bin/cat.exe→D:\Git\usr\bin\cat.exe(spawnable)../elem/namestays relative → re-resolves at spawn cwd → post-cdENOENT semantics of rubash#2696 preserved.checkhashprobe now stats the real file instead of a<cwd>\d\...ghost path.Display faces are unaffected:
hash -t/type/command -v/hash -l/BASH_CMDSreadphash_search/hashed_entriesdirectly and still print/d/...forms (verified).GNU anchors
execute_cmd.c:6126-6133shell_execve—execve(command, args, env)runs the recorded string verbatim.findcmd.c:365-380search_for_command—phash_searchconsult before the PATH walk.hashcmd.c:126-191phash_searchCHKDOT/RELPATH serve arm.subst.ccommand_substitute— comsub captures stdout only; stderr stays inherited, so genuine spawn failures do reach the terminal (routing was already correct).Test evidence
/usr/local/bin/bash5.3.20(1)-release: stdout byte-identical, stderr empty (was: one extra/d/...cat.exeline).a41909d3epre-fix, green with fix.executor::path::tests::hash_consult_returns_spawnable_fs_path_for_display_spelling: red before (/c/...returned), green after.cargo test --libboth sides: head {issue2084_session_end_restores_host_process_state} / base {same} — diff empty (1375 passed / 1 baseline fail each).C:\Program Files\Git\usr\bin);issue3551_hash_chkdot4/4 green.RUSTFLAGS="-D warnings" cargo check --lib --tests: 0 warnings.rustfmt --check src/executor/path.rs: clean.scripts/check-marker-literals.py: OK.cargo test --test regression golden_issue1230_exec_redirect_undocannot go green on this box —minimal_path()needsC:\Program Files\Git\usr\bin, absent here (Git lives atD:\Git); it fails identically before/after for missing coreutils, unrelated to this fix. CI runners have the expected layout.Generated with Devin