Skip to content

a malformed parameter expansion is silently swallowed: wrong value, no diagnostic, status 0 (breaks set -e / && / ||) #758

Closed

Description

@caomengxuan666

Summary

A malformed parameter expansion that bash rejects is silently swallowed by niu, as an empty string, with status 0 and no diagnostic. The command that bash abandons runs to completion here, so any set -e / if ! cmd / && guard sees success.

Verified against WSL GNU bash 5.3.0; LF script file; stdout and stderr captured separately.

1. Junk after a subscripted expansion

v=abc
echo "[${v[0]x}]"; echo "status=$?"
stdout stderr status
GNU bash (nothing — the command is abandoned) [${v[0]x}]: bad substitution 1
niu / rubash [] (nothing) 0

The whole word is discarded by bash before it expands; niu expands it to the empty string and reports success.

2. Truncated substring syntax

v=abcdef
echo "[${v:}]"; echo "status=$?"
stdout stderr status
GNU bash (nothing) [${v:}]: bad substitution 1
niu / rubash [] (nothing) 0

3. Lower severity, same issue: 1 << -1

echo "$(( 1 << -1 ))"
result
GNU bash -9223372036854775808, status 0 (the shift counts as unsigned)
niu / rubash error, no output, status 1

Both are defensible readings of an undefined shift, so this one is filed only as context — items 1 and 2 are the finding.

Why items 1–2 are high severity

  • set -e, if ! cmd; then, cmd && next and cmd || fallback all key off the status. Here the command that bash refuses to run reports 0.
  • The value is wrong and silent: an empty string instead of an error, with no message on either stream.
  • ${…} forms with junk after ], and truncated ${v:}, are easy to produce from generated scripts and from string manipulation.
  • It is the same "silently different" profile as the other members of this family — no error, just a different value and a different status.

Method

LF script file; niu (installed 1.4.0, rubash git e785c3c8f610) and WSL GNU bash 5.3.0; stdout/stderr captured to separate files. Note that in both shells the status=$? echo on the same line is affected by the abort, so the status was read with the failing command on its own line.

Activity

  1. added
    bug
    P1-high
    area:expansion
    family:S1
    on Oct 17, 2026
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

    P1-higharea:expansionbugfamily:S1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions