Skip to content

[bug] mapfile < missing-file: redirect-open failure is silently swallowed (no diagnostic, rc=0; GNU prints 'No such file or directory' and rc=1) #324

Closed

Description

@caomengxuan666

Found by ecosweep3 lane (pure-bash-bible corpus, sections 030/031/032; carrier release build of 6106961). read/while-read redirect errors behave correctly; mapfile specifically loses them.

Reproducer (target/probe-out/p4.sh, p5.sh)

read -r x < missing_file_A
echo "after1 rc=$?"
mapfile -t arr < missing_file_B
echo "after2 rc=$?"

GNU bash 5.3.0:

after1 rc=1
after2 rc=1
script: line 2: missing_file_A: No such file or directory
script: line 4: missing_file_B: No such file or directory

rubash:

after1 rc=1
after2 rc=0
script: line 2: missing_file_A: No such file or directory

(mapfile line: no diagnostic at all, rc 0.)

GNU anchor

Redirection failures for builtins: redir.c do_redirection_internal open error propagates via redir_error to execute_builtin/execute_builtin_command (execute_cmd.c builtin path) which prints the shell-name-prefixed diagnostic and returns 1 — identical to the read path. rubash's mapfile dispatch evidently performs the redirect open after/around the point where the error can be reported.

Impact

pbb 'Get the first/last N lines of a file' + 'read a file to an array' sections: GNU emits an error line per call, rubash emits nothing — silent data loss on missing input (mapfile leaves the array untouched with rc=0, scripts proceed as if the file were empty).

Activity

  1. added
    bug
    gnu-baseline
    on Sep 29, 2026
  2. added a commit that references this issue on Sep 29, 2026
  3. caomengxuan666 commented on Sep 29, 2026

    @caomengxuan666
    MemberAuthor

    Fixed by wt14/pbbfix (e76633e, master): three mapfile dispatch sites skipped the builtin redirect precheck, so a failed bare read fell into the empty-input path clearing the array with rc=0. GNU applies redirections BEFORE the builtin body (execute_cmd.c:4787+): error rc=1, array untouched, redirect failure takes priority over the identifier check. Repro matrix all identical (platform residual only: mapfile < . cannot open a directory on Windows - same known family as read).

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

    buggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions