Repository navigation
Description
Found by ecosweep4 lane (wt22/nest22, corpus: pre-commit testing/get-coursier.sh, worktree base a522eb3, release build; oracle WSL GNU Bash 5.3.0 /usr/local/bin/bash, script-file runs).
Reproducer (minimal)
set -euo pipefail; false; echo NOPE — rubash prints NOPE and exits 0; GNU aborts at false with rc=1.
# min.sh
set -euo pipefail
false
echo NOPE-TOP- rubash:
NOPE-TOP, rc=0 (artifact: target/issue-suites/results/ecosweep4/pc/c9.sh) - GNU 5.3.0: no output, rc=1
Nounset is dropped the same way:
set -euo pipefail
echo "val=${UNSET_XYZ}"
echo NOPE- rubash:
val=+NOPE, rc=0 (artifact: .../ecosweep4/pc/w4.sh) - GNU:
min.sh: line 2: UNSET_XYZ: unbound variable, rc=1
Controls (correct in rubash, proves it is the bundling with -o that breaks it):
set -ealone /set -eu→ errexit works (abort rc=1)set -e -u -o pipefail(separate words) → works (see mechanism: side effects happen before the bail)set -eo pipefail/set -euo pipefail/set -uo pipefail→ brokenset -o pipefailalone → pipefail itself IS set correctly; only the short flags bundled in the same word are lost
Real-world hit: pre-commit testing/get-coursier.sh (header set -euo pipefail): a failing chmod +x (missing file) left the script rc=0 under rubash (GNU rc=1) — silent-success masking of errors. set -euo pipefail is arguably the single most common script header in the ecosystem, so every such script's error handling is inert under rubash unless it uses separate set -e/set -u words.
Root cause (GNU C source as spec)
GNU applies every flag char in the same word in one pass: builtins/set.def:716-772 set_builtin() — the while (flag_name = *++arg) loop dispatches each char EITHER to set_minus_o_option (the 'o' case with its operand from list->next, set.def:726-766) OR to change_flag (flag_name, on_or_off) (set.def:767). There is no bundling restriction: -euo pipefail applies e, u, and o pipefail in that order.
Rubash has a two-path split that loses the bundle:
- Fast path
src/executor/shell_options.rs:593 apply_simple_set_flags(): iterates args; if ANY char of an arg is not a supported short flag itreturn false— and'o'is (correctly) not in the short-flag table (is_supported_short_set_flag, shell_options.rs:916;short_set_flag_option, src/executor/support_names.rs:380 has no'o'). So for["-euo", "pipefail"]it applies NOTHING (the whole call bails at the first arg) and hands off. - Slow path
src/builtins/set.rs:86 set_with_io(): the char loop (set.rs:119-196) only applies'o'(set.rs:121-157, viaset_shell_option) and'r'(set.rs:160-179); plain short flags are validated againstSET_FLAGS(set.rs:182-195, error-only) but never applied — the author assumed the fast path owned them.
Net effect: -e/-u bundled before -o in the same word are validated and then silently discarded; only the -o option lands.
Note the asymmetry that makes set -e -u -o pipefail work: apply_simple_set_flags applies -e and -u from the first two words before it hits -o and returns false, then set_with_io applies pipefail.
Suggested fix direction (for the owning lane)
Make set_with_io (the real parser) own full set.def semantics: in its char loop, apply each plain short flag through the same mapping the fast path uses (including the __RUBASH_ERREXIT/__RUBASH_XTRACE markers for 'e'/'x', shell_options.rs:614-649), so the slow path is complete on its own. Alternatively teach apply_simple_set_flags to consume -o's operand — but the two-path split invites exactly this class of drift; the slow path being complete is the invariant that matches GNU (set.def has only one loop).
Verification bar (per AGENTS)
- Matrix vs WSL GNU Bash 5.3.0 script files:
{-e,-u,-x,-f,-C} × {bundled with -o, separate word before -o, alone} × {on(-), off(+)} × {failure triggers: false, unbound var, failed redirect}— rc + stderr parity. - Existing suites known to touch this family:
set-e.tests,options behaviours— rerunscripts/true-baseline.sh set-eafter the fix.
Artifacts
- Harness + verdicts:
target/issue-suites/results/ecosweep4/pc/(16 cases, 15/16 byte-identical; the 1 red is this bug via get-coursier.sh) - Minimal probes:
.../pc/{c4,c5,c6,c7,c8,c9,w4}.shwith.rub.out/.gnu.outpairs
Activity
docs(corpus): ecosweep4 section - dev-toolchain shell layer wave + B …
fix(#358): apply bundled short flags in set's slow path (set -euo pip…
test(#358 followup): conformance probes become GNU-truthful now that …
caomengxuan666 commentedon Sep 30, 2026
Fixed by wt22/p0fix (3f32182 + eeb4ff3, master 3ade4b2): the fast path bailed the WHOLE word on a bare o; the slow path (set_with_io) validated but never APPLIED short flags. The slow path is now the full GNU two-phase port (internal_getopt prescan validate-first bashgetopt.c:76-137, single apply loop set.def:716-772 where o consumes the next word and change_flag runs per-character), all three duplicated flag-table copies collapsed into one apply_short_set_flag truth table (the positional copy was also missing n/noexec), and the fast path gained whole-args prevalidation. 25-case file matrix (bundled/split/solo x on/off x false/unbound/redirect-failure/invalid-flag edges incl. -opipefail/-eo/-eox) byte-identical to WSL GNU 5.3.0; set-e/set-x suites 0 diff; the ecosweep4 pre-commit corpus and direnv's 52 drivers re-verified (every semantic case green). 14 regressions. Bonus: three conformance probes had encoded this bug as expected behavior (they die on unbound/errexit under GNU too) — corrected to GNU-truthful.
fix(tests): sandbox issue358 probe dir under temp_dir (#358)\n\nmkdir…