Skip to content

[bug] P0 set -euo pipefail / set -eo pipefail silently drops -e and -u (bundled short flags before -o are never applied) — set -e appears off, scripts run past failures #358

Closed

Description

@caomengxuan666

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 -e alone / 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 → broken
  • set -o pipefail alone → 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:

  1. 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 it return 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.
  2. Slow path src/builtins/set.rs:86 set_with_io(): the char loop (set.rs:119-196) only applies 'o' (set.rs:121-157, via set_shell_option) and 'r' (set.rs:160-179); plain short flags are validated against SET_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 — rerun scripts/true-baseline.sh set-e after 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}.sh with .rub.out/.gnu.out pairs

Activity

  1. added
    bug
    on Sep 30, 2026
  2. added 3 commits that reference this issue on Sep 30, 2026
  3. caomengxuan666 commented on Sep 30, 2026

    @caomengxuan666
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions