Skip to content

[bug] set -u nounset check skipped in for-list/case-subject/[[ ]]/herestring #1130

Closed

Description

@caomengxuan666

[bug] set -u nounset check skipped in 4 word-expansion positions (for-list, case subject, [[ ]], herestring)

One root cause — nounset enforcement missing on these expansion paths (simple-command args, assignment RHS, array assignment, (( )), [ ], redirect targets, ${v:-d} all correctly error in both):

set -u
for s in $q hello; do echo "S=$s"; done        # also for s in "$w" foo
# GNU: q: unbound variable, rc=1, loop never runs / niu: prints S=hello (or S= + S=foo), rc=0

set -u
case "$q" in x) echo x;; *) echo other;; esac  # quoted or not
# GNU: q: unbound variable, rc=1 / niu: prints other, rc=0

set -u
[[ $v != *o* ]] && echo yes || echo no         # LHS, RHS, unary, bare
# GNU: v: unbound variable, rc=1 / niu: prints yes, rc=0
# ([ -n "$v" ] errors correctly in both — [[ ]]-specific)

set -u
cat <<< prefix$p | wc -w
# GNU: p: unbound variable, prints 0 / niu: no error, prints 1
# (fully-quoted <<< "hs $p" errors in both — only unquoted/mixed forms skip)

Found by differential fuzzing (3500 snippets, 31 raw hits → this one novel family; =~ error-text hits are #1058-family, /dev/stdout double-open hit is known #1068). P2-medium: silent empty expansion under set -u defeats strict-mode scripts; wrong branch/loop behavior + exit code flipped 1→0.

Env: niubash 1.4.4 / rubash engine (master ~2026-10), GNU bash 5.3.20 aarch64-linux-android as oracle.

Activity

  1. added
    bug
    gnu-baseline
    area:expansion
    P2-medium
    on Oct 22, 2026
  2. caomengxuan666 commented on Oct 23, 2026

    @caomengxuan666
    MemberAuthor

    Re-verified on master (263ce53f): partially fixed by #1181 (commit a5c3fb5). for-list, case-subject, [[ ]], and standalone herestring all now raise unbound variable correctly.

    Residual still diverging — unquoted/mixed herestring inside a pipeline:

    set -u
    cat <<< prefix$p | wc -w
    # GNU 5.3.20:  p: unbound variable, prints 0
    # rubash:      no error, prints 1   (skips nounset check in pipeline position)
    

    Standalone cat <<< prefix$p errors correctly; only the pipeline-element form leaks. Leaving open for the residual.

  3. caomengxuan666 commented on Oct 23, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by #1181 (2026-10-22/23 bulk GNU-parity wave): landed as a dedicated commit referencing this issue, covered by the audit differential suite (tests/fixtures/audit/), and re-verified byte-for-byte against a GNU bash 5.3.20 oracle; master CI (ff1a555) runs the suite green.

    Closing now to restore the linkage: GitHub's closing-reference parser only honored the first entry of #1181's long Fixes list, so this stayed open after the fix landed. If anything still reproduces on current master, reopen with a transcript and it returns to the fix queue.

  4. caomengxuan666 commented on Oct 23, 2026

    @caomengxuan666
    MemberAuthor

    Re-verified on niu 1.4.4 (rubash 1b14a3d) vs GNU bash 5.3.20. for-list and case-subject now error on both (fixed by #1181); residual divergences below.

    set -u; [[ $v != *o* ]] && echo yes || echo no

    bash: v: unbound variable, script exits 1; niu: same error text but script exits 0 (no yes/no printed either side).

    set -u; cat <<< prefix$p | wc -w

    bash: p: unbound variable on stderr, stdout 0; niu: no error, stdout 1.

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

    P2-mediumarea:expansionbuggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions