You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[bug] P0 External script files (shebang scripts) execute IN-PROCESS: variables assigned by the script leak into the caller's scope — direnv stdlib use()/log_status() stub chain corrupted ('use_log: command not found') #363
Found by ecosweep4 lane (wt22/nest22; corpus: direnv stdlib.sh per-function drive; worktree base a522eb3, release build; oracle WSL GNU Bash 5.3.0 script-file runs).
same $$ inside the script and the caller (a real child shell would report its own pid),
exit 3 did NOT terminate the caller (contained),
cd /tmp did NOT persist (cwd restored),
exit status propagated correctly.
So rubash emulates external script execution by interpreting the script inside the current shell with cwd/exit containment — but variable assignments are not isolated (and $$ is the caller's). Works via direct path AND via PATH command lookup (both probed).
Real-world hit
direnv stdlib.sh use() (stdlib.sh:1132-1137):
use() {
local cmd=$1
log_status "using $*"shift"use_$cmd""$@"
}
log_status() runs the direnv binary ("$direnv" log -status "$*"). Under rubash, whatever variables the (stubbed or real) child script assigns — cmd is an extremely common name — clobber the caller's locals. In this lane's harness the stub's cmd=$1 turned "use_$cmd" into use_log → use_log: command not found (rc=127) for use/use_julia/use_node/use_nodenv/use_rbenv/use_flake/use_guix — the entire use family dies. Any real tool invoked by an .envrc that internally assigns a variable colliding with an .envrc/direnv local silently corrupts it. GNU anchor: execute_cmd.c execute_disk_command → fork/exec (execute_cmd.c:5740s family); the child is a separate process whose variable table never touches the parent's (variables.c: no such sharing exists).
The in-process script executor needs a full variable-table save/restore (at minimum: unset/restore every variable the script assigns, like GNU's fork isolation), or a real child-process boundary. Note cwd/exit are already contained — variables are the missing wall. $$ inside such scripts is a secondary divergence (caller pid instead of child pid).
ecosweep4 follow-up evidence (same lane, wt22/nest22): the in-process script execution also leaks readonly attributes across script invocations.
bats-core runs bats-exec-test as an external script once per test. Under rubash, once a test's frame declares a variable readonly, the NEXT test's in-process run inherits the readonly mark and its unset fails:
libexec/bats-core/bats-exec-test: line 53: unset: BATS_RETRY_RETURN_CODE: cannot unset: readonly variable
libexec/bats-core/bats-exec-test: line 53: unset: BATS_TEST_TAGS: cannot unset: readonly variable
GNU (fresh process per test): no such errors. Verified the plain readonly-unset semantics are symmetric (subshell/function unset of a readonly var fails on both shells — probe target/issue-suites/results/ecosweep4/rupro.sh), so the divergence is specifically the leaked attribute, not unset behavior.
Artifacts: rub-only stderr in target/issue-suites/results/ecosweep4/bats/{rub/file_setup_teardown.bats.err, rub/junit-formatter.bats.out} (22 lines accumulated), GNU side empty.
Fixed by wt22/p0fix (83fc21e, master 3ade4b2): classified as DESIGN (Windows has no kernel #!, in-process execution is the established exec model) — but the direct-script branch was the one remaining fork-model caller: typed-store writes leaked through without rollback and children saw parent UNEXPORTED variables. GNU anchor: execute_cmd.c:6139-6233 shell_execve (#! = new process) AND the ENOEXEC tail 6237-6260 -> shell.c:429-464 shell_reinitialize — BOTH are fresh shells inheriting only exported variables (WSL-proven: an unshebang +x child prints PLOCAL=[unset]). Fix: the direct branch passes exec_model_entry=true (one flag, reusing the existing full fresh-shell isolation machinery). Issue probes + 9 new tests byte-aligned; direnv use/use_node/use_vim turn green (28->31/52). $$ documented residual.
Activity
caomengxuan666 commentedon Sep 30, 2026
ecosweep4 follow-up evidence (same lane, wt22/nest22): the in-process script execution also leaks readonly attributes across script invocations.
bats-core runs
bats-exec-testas an external script once per test. Under rubash, once a test's frame declares a variable readonly, the NEXT test's in-process run inherits the readonly mark and itsunsetfails:GNU (fresh process per test): no such errors. Verified the plain readonly-unset semantics are symmetric (subshell/function
unsetof a readonly var fails on both shells — probe target/issue-suites/results/ecosweep4/rupro.sh), so the divergence is specifically the leaked attribute, not unset behavior.Artifacts: rub-only stderr in target/issue-suites/results/ecosweep4/bats/{rub/file_setup_teardown.bats.err, rub/junit-formatter.bats.out} (22 lines accumulated), GNU side empty.
docs(corpus): ecosweep4 section - dev-toolchain shell layer wave + B …
fix(#358): apply bundled short flags in set's slow path (set -euo pip…
fix(#363): direct external scripts run as fresh shells — assignments …
caomengxuan666 commentedon Sep 30, 2026
Fixed by wt22/p0fix (83fc21e, master 3ade4b2): classified as DESIGN (Windows has no kernel #!, in-process execution is the established exec model) — but the direct-script branch was the one remaining fork-model caller: typed-store writes leaked through without rollback and children saw parent UNEXPORTED variables. GNU anchor: execute_cmd.c:6139-6233 shell_execve (#! = new process) AND the ENOEXEC tail 6237-6260 -> shell.c:429-464 shell_reinitialize — BOTH are fresh shells inheriting only exported variables (WSL-proven: an unshebang +x child prints PLOCAL=[unset]). Fix: the direct branch passes exec_model_entry=true (one flag, reusing the existing full fresh-shell isolation machinery). Issue probes + 9 new tests byte-aligned; direnv use/use_node/use_vim turn green (28->31/52). $$ documented residual.
fix(tests): portable probe dir and shebang in script-isolation tests (#…
fix(tests): gate Windows-path literal rows to Windows (#555) (#694)