Repository navigation
fix(#587,#588): pipeline function lookup + PATH-assignment-owned command resolution - #594
Merged
Merged
Conversation
…ommand
GNU contract: execute_pipeline (execute_cmd.c:2620) routes every
element through execute_command -> execute_simple_command, which
resolves functions BEFORE the PATH search - special builtins first
(execute_cmd.c:4657-4663, posix-only preclusion of find_function),
then func = find_function(words->word->word) (execute_cmd.c:4674-4677),
execute_builtin_or_function dispatch (execute_cmd.c:4837-4861), and
execute_from_filesystem -> execute_disk_command (execute_cmd.c:4919-4925)
only when both lookups missed. A function shadows every ordinary
builtin, and a member naming a function never reaches the disk.
Two dispatch sites skipped the function table:
1. execute_pipeline_stage_inner classified the stage by its hardcoded
ordinary-builtin arms (echo/printf/cat/head/sed/grep/wc/tr/true/
false/trap) and execute_builtin_pipeline_stage before any function
lookup, so 'echo(){ printf ...; }; echo hi | cat' ran the builtin
echo where GNU 5.3.0 runs the function (WSL probe 2026-10-13:
FUNC-ECHO). The default arm below those arms did resolve functions,
which is why plain non-builtin-named sequential stages looked fine.
2. The concurrent native-pipeline fast paths classified members with
is_shell_builtin_name only and handed everything else straight to
find_user_command: concurrent_external_stage_spec (Windows) and the
unix twin loop in execute_external_pipeline_concurrently. So
'date(){ echo FAKE; }; date | cat' executed the real date(1) (GNU:
FAKE, PIPESTATUS '0 0') and 't(){ ...; }; t git log | wc -l'
silently ran a 0-byte t stub found on PATH (GNU: 1) - only when a
pipeline had no function-named member did the OS-pipe path keep its
concurrency.
Fix: gate the concurrent spec builders on function_name_for_command_word
of the member's already-expanded first field (bail to the sequential
loop, which owns subshell function semantics), and add a find_function-
first gate in the sequential stage dispatch before the hardcoded arms,
keeping execute_function_command_invocation's posix special-builtin
exception (command_prepare.rs; execute_cmd.c:4657-4663). Expanded-word
members ('v=date; $v | cat') resolve through the same gate on the
concurrent paths and through the default arm's expansion on the
sequential path.
WSL GNU bash 5.3.0 byte matrix (script-file probes, target/probe587/
g2.sh, g5.sh): date|cat -> FAKE with PIPESTATUS 0 0, t git log | wc -l
-> 1, echo/wc/cat shadowing functions run as pipeline members,
$(d | cat) -> FAKE, 'set -o pipefail; d(){ return 3; }; d | cat' -> 3.
New tests/issue587_pipeline_function_lookup.rs asserts all of these
plus posix-mode shadowing, three-member pipelines, and the 127
diagnostic for a genuinely missing external member.
…ces stand down
GNU contract: command search walks the PATH variable verbatim -
search_for_command feeds value_cell(path) straight to the walk
(findcmd.c:383-386, empty PATH normalized to .), and
find_user_command_in_path (findcmd.c:623-697) consults nothing beyond
the variable's elements: directories that resolve nothing yield no
command and the caller reports 127. A PATH-less shell gets a real
startup assignment instead (variables.c:550 set_if_not(PATH,
DEFAULT_PATH_VALUE)), not an out-of-band lookup namespace.
Rubash's Windows hosts keep two out-of-band namespaces that stand in
for that startup default - the winuxcmd dispatcher
(find_user_command_uncached, path.rs) and the /bin display paths
(command_path/command_paths, lookup_paths.rs) - but both answered
REGARDLESS of PATH state, so after a starving assignment
'PATH=/nonexistent; hash -r; ls; echo $?' printed a real listing with
rc 0 and 'command -v ls' reported /bin/ls, where GNU bash 5.3.0
answers 127 and rc 1 (WSL probes, target/probe587/g3.sh g4.sh
2026-10-13; tempenv and export assignments alike: 127).
The namespaces are intentional for the never-set state: a host with no
usable PATH still needs its tools, exactly like GNU's startup default.
The broken direction was only that an explicit assignment - plain,
export, tempenv prefix, even unset - did not retire them.
Fix: init.rs records the imported (normalized) PATH once at the startup
boundary (__RUBASH_INITIAL_PATH, contains_key guard so subshell and
command-substitution executors stay on the process's original
snapshot), and path::path_is_user_owned compares the live PATH against
it. While PATH equals the imported value the fixture answers as before;
once a shell-level assignment moves resolution under the script's
control - any value change, or unset (GNU path_value returns NULL,
findcmd.c:279-293, and the walk never runs) - the dispatcher and the
/bin display paths stand down and find_user_command answers from the
walk alone (findcmd.c:623-697). Prepending/shadowing
('PATH=$dir:$PATH') keeps working through the walk itself; only the
starvation direction was ever broken.
New tests/issue588_path_starve_lookup_contract.rs asserts the 127/rc-1
contract for plain, export, tempenv, empty and unset PATH in default
and posix modes, builtin/function independence under starvation, and
the preserved prepend, identity and rejoin resolutions.
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 #587. Closes #588.
Two independent execution-plane fixes, one commit each.
#587 — pipeline members resolve shell functions before the disk command
Symptom:
date(){ echo FAKE; }; date | catexecuted the realdate(1) (GNU 5.3.0 printsFAKE,PIPESTATUS0 0);t(){ ...; }; t git log | wc -lsilently ran a 0-bytetstub found on PATH. Non-pipeline calls were fine.Root cause: two dispatch sites skipped the function table.
execute_pipeline_stage_inner(src/executor/pipeline_exec.rs) classified stages through its hardcoded ordinary-builtin arms (echo/cat/wc/... plusexecute_builtin_pipeline_stage) before any function lookup — GNU'sfind_function(execute_cmd.c:4674-4677) precedes ordinary-builtin classification, so functions shadow those names inside pipelines too.concurrent_external_stage_spec, Windows, and the unix twin loop inexecute_external_pipeline_concurrently) admitted members onis_shell_builtin_namealone and spawned everything else straight offfind_user_command.Fix: GNU
execute_pipeline(execute_cmd.c:2620) routes every element throughexecute_simple_command, where functions resolve beforeexecute_from_filesystem(execute_cmd.c:4919-4925). Both spec builders now bail to the sequential loop when a member's expanded first field names a function, and the sequential stage dispatch gained a find_function-first gate ahead of the hardcoded arms (keeping the posix special-builtin exception, execute_cmd.c:4657-4663 /execute_function_command_invocation).Tests:
tests/issue587_pipeline_function_lookup.rs(11 cases) — both issue repros,$v-expanded members, echo/wc/cat shadowing, posix mode, three-member pipelines, PIPESTATUS, pipefail through areturn 3function, and the 127 diagnostic for a genuinely missing external member.#588 — a PATH assignment owns command resolution; fixture namespaces stand down
Symptom:
PATH=/nonexistent; hash -r; ls; echo $?printed a real listing with rc 0 andcommand -v lsreported/bin/ls; GNU answers127/ rc 1 (also forexport PATH=...and tempenvPATH=... cmd).Root cause: the Windows fixture namespaces — the winuxcmd dispatcher (
find_user_command_uncached,src/executor/path.rs) and the/bindisplay paths (command_path/command_paths,src/executor/lookup_paths.rs) — answered regardless of PATH state, so any explicit assignment lost to the fixture whenever its directories resolved nothing.Fix: anchored on vendored
find_user_command_in_path(findcmd.c:623-697): the walk consults only the PATH variable's elements; the only default a PATH-less shell gets is a real startup assignment (variables.c:550set_if_not("PATH", DEFAULT_PATH_VALUE)). The fixture namespaces stand in for exactly that default:init.rsrecords the imported (normalized) PATH once per process (__RUBASH_INITIAL_PATH),path_is_user_ownedcompares the live PATH against it, and once a shell-level assignment — plain,export, tempenv, orunset(path_value NULL, findcmd.c:279-293) — moves resolution under the script's control, the fixture stands down and the walk answers alone (127). Never-set/never-assigned hosts keep the fallback; prepend/shadow (PATH=$dir:$PATH) keeps working through the walk itself.Tests:
tests/issue588_path_starve_lookup_contract.rs(12 cases) — 127/rc-1 contract for plain/export/tempenv/empty/unset PATH in default and posix modes, builtin+function independence under starvation, and preserved prepend, identity, and rejoin resolutions.Verification
cargo checkclean;RUSTFLAGS="-D warnings" cargo check --all-targets --keep-goingfailure set identical to origin/master (7 pre-existing broken test targets, none touched by this branch);cargo fmt --checkclean.RUST_TEST_THREADS=1 cargo test --no-fail-fast, run on origin/master and on this branch: failure sets identical bidirectionally (commempty, 33 pre-existing local failures each; the 8 transientbashdb_compatentries were a missingtarget/bashdb-cleanfixture in the worktree, confirmed equal 10=10cli_testssets after fixture setup).date|cat→FAKE/0 0,t git log | wc -l→1, starvation 127/rc-1 matrix,$(d | cat), pipefail-through-function).