Skip to content

[bug] exec-installed permanent stdin redirect ignored inside pipeline components #1102

Closed

Description

@caomengxuan666

[bug] exec-installed permanent stdin redirect ignored inside pipeline components (stdin-only)

echo hi | { exec </dev/null; head -1; echo "rc=$?"; }
# GNU bash 5.3:  (empty), rc=0 (head reads /dev/null)
# niu:           hi, rc=0 — the pipe is still stdin after exec

Also: exec < regular-file (bash reads FILEDATA, niu reads pipe), exec <&- (bash empty, niu pipe data), in { } groups, ( ) subshells, middle pipe positions. NOT affected (verified same): exec >f / exec 2>f / exec {fd}>f in pipe groups, all exec forms at top level or plain groups/subshells/functions, exec {r}<f + cat <&$r workaround, per-command < file / <<< / <&0. Medium: scripts re-pointing stdin mid-pipeline silently read stale pipe data with rc=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:fd
    family:S3
    P2-medium
    on Oct 22, 2026
  2. caomengxuan666 commented on Oct 22, 2026

    @caomengxuan666
    MemberAuthor

    Sibling nuance from builtin-pipe fast-path sweep (read/mapfile instead of head): echo hi | { exec 0<&-; read x; ...; } → bash read error: Bad file descriptor rc=1 / niu reads stale hi rc=0; exec 0</dev/null + mapfile → bash n=0 / niu n=1. BUT exec 0<regular-file + read matches on both (FILEDATA) — so the leak is specific to non-regular-file targets (null/closed) for read/mapfile, unlike head/cat which leak everything. Same root family, different boundary.

  3. caomengxuan666 commented on Oct 23, 2026

    @caomengxuan666
    MemberAuthor

    Verified fixed on master (a55e4d6) — fixed by b9fd97a 'fix(executor): exec-rebound fd 0 shadows the pipeline stage stdin buffer (#1102)'.

    Repro against release build of current master:

    $ echo hi | { exec </dev/null; head -1; echo "rc=$?"; }
    rc=0
    $ echo hi | { exec < in.txt; head -1; echo "rc2=$?"; }
    FILEDATA
    rc2=0
    $ echo hi | { exec <&-; head -1; echo "rc3=$?"; }
    rc3=0
    

    The reported symptom is gone: the exec-installed stdin redirect is honored inside pipeline components — pipe data no longer leaks through (matches GNU for exec </dev/null and exec < file).

    One residual note for a possible follow-up: for exec <&-, GNU head fails EBADF with rc=1 while rubash's head sees an empty stream (rc=0). The same divergence occurs at top level outside pipelines, so it is a general fd-0-closed fidelity edge, not the pipeline bug reported here.

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:fdbugfamily:S3gnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions