Skip to content

fix(executor): report E2BIG wording for an oversize command line (Refs unixwin/niubash#993 S4) - #3712

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/993-s4
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/993-s4

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

  • spawn_error_diagnostic matched the E2BIG/ENOMEM preemption (execute_cmd.c:6156 file_error -> sys_error -> strerror) by unix errno values only. On Windows an lpCommandLine past CreateProcess's 32767-char limit surfaces as ERROR_FILENAME_EXCED_RANGE (206), which the generic strerror table renders File name too long — correct for path opens (ENAMETOOLONG's Win32 twin), wrong here.
  • Raw os error 206 is now folded into the e2big class inside the spawn classification only — the posix_errors table mapping stays untouched. Both the sampling short-circuit and the rendered message honor it; status stays EX_NOEXEC (126, execute_cmd.c:6143).

GNU anchors

  • execute_cmd.c:6143 status switch (ENOENT->127 else 126)
  • execute_cmd.c:6156-6159 i == E2BIG || i == ENOMEM -> file_error (command)

Verification

  • Issue repro (200 KiB arg vs $COMSPEC): ...cmd.exe: Argument list too long rc=126 (was File name too long).
  • New tests/niubash993_e2big_wording.rs: 3/3 (spawn wording, rc=126, exec builtin wording — same classification path at builtins/exec.rs:794).
  • posix_errors unit tests 4/4; spawn regression files (issue3091/3420/3198) green except two issue3198 deleted-cwd assertions that fail identically on clean master (path-separator expectation, unrelated).

Generated with Devin

…unixwin/niubash#993 S4)

`spawn_error_diagnostic` classified the E2BIG/ENOMEM preemption
(execute_cmd.c:6156 file_error -> sys_error -> strerror) by the unix
errno values only. On Windows the same condition — an lpCommandLine
past CreateProcess's 32767-char limit — surfaces as
ERROR_FILENAME_EXCED_RANGE (206), which the generic strerror table
renders "File name too long" (correct for path opens, ENAMETOOLONG's
Win32 twin). Git Bash prints "Argument list too long", so a
200-KiB-argument spawn read `python.exe: File name too long` where GNU
reports `Argument list too long`.

Map raw os error 206 into the e2big class inside the spawn
classification only — the table mapping itself stays 206 -> "File name
too long" because a path-open failure with an overlong name is
genuinely ENAMETOOLONG. The classification short-circuit and the
rendered message both honor it: status stays EX_NOEXEC (126,
execute_cmd.c:6143).

Verification: issue repro `arg=$(printf 'a%.0s' {1..200000});
"$COMSPEC" x "$arg"` now prints `...cmd.exe: Argument list too long`
rc=126 (was `File name too long`); new tests/niubash993_e2big_wording
3/3 (direct spawn wording, rc=126, exec-builtin wording);
posix_errors unit tests 4/4; spawn regression files green except the
two issue3198 deleted-cwd assertions which fail identically on clean
master (path-separator expectation, unrelated).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit e7fb037 into master Nov 15, 2026
7 of 11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/993-s4 branch November 15, 2026 17:37
caomengxuan666 added a commit that referenced this pull request Nov 16, 2026
…3734)

* executor: port GNU async-stdin verdict to pipe-fed pipeline elements

Refs #3605

exec13.sub's pipe-fed compound elements (`echo x | ( cat & wait )`,
`| { cat & wait; }`, function elements) lost their lines: the async
child spawned with /dev/null stdin because the element clone never
inherited the "my stdin is a pipe" verdict.

GNU anchors (bash-5.3 vendored tree):

- execute_cmd.c:4570 — the forked element child does
  `stdin_redir |= (pipe_in != NO_PIPE)`; a pipe-connected element's
  async spawns read the pipe, not /dev/null.
- execute_cmd.c:1733 — `execute_subshell_command` ASSIGNS
  `stdin_redir = (own fd-0 redirects) || (pipe_in != NO_PIPE)`; a
  nested `( )` clears an enclosing verdict, and the element's own
  `< file` replaces the pipe via do_redirections.
- execute_cmd.c:1759-1764 — the :826 `stdin_redir = redirects` assign
  for shell control structures runs AFTER do_redirections consumed
  the element's fd-0 redirect, so it must not re-set the flag.
- eval.c:181 — only reader_loop clears stdin_redir between commands;
  evalstring.c's parse_and_execute does not, so a clone replaying a
  pre-parsed element list must not clear either.
- jobs.c:1743/nojobs.c child_setup — the async child consults the
  verdict when picking /dev/null vs inherited fd 0.

Port:

- `execute_pipeline_stage` gains a `stdin_is_pipe` parameter; the
  stage entry ORs it into `shell_state.stdin_redir` and the epilogue
  restores the caller's flag. Real-OS-pipe stage call sites (loop
  stages index > 0, streaming tail/mid) pass true; producer/stage-0
  and the timed-read followup pass false. GNU's lastpipe quirk
  (prev = NO_PIPE before dispatching the last element) means the
  lastpipe path needs no marker.
- New one-shot `element_pipe_stdin` Cell on ShellState: set on the
  compound-stage clone, consumed at the clone's own compound
  dispatch — the `( )` :1733-style assign
  (`own fd-0 redirects || marker`) and the :826-style assigns in
  `command_execute`/`execute_brace_group_pipeline`, both of which
  GNU skips for pipe-connected elements.
- ast_exec's per-command reader-loop clear now only fires at
  subshell_depth == 0 (eval.c:181); a stage clone's body walk is not
  a reader loop.
- `bind_command_fd0_input` drops the FUNCTION_STDIN(+OFFSET) mirror
  after binding a real fd-0 endpoint (file, procsub, net): GNU's
  do_redirections replaces fd 0 wholesale, so a stale pipe mirror
  must not shadow the bound file for `inherited_async_stdin`.

Verification vs GNU bash 5.3.20 (script files, byte-identical
stdout/stderr/rc): exec13.sub shapes x1/x1a/x2b/x3/x3a incl. GNU's
empty x2/x2a, x3b + lastpipe forms, and a 13-form probe matrix
(pipe-fed `( )`/`{ }`/if/while/for/case/select/coproc elements,
element-own-`< file` override, nested-clear assign semantics,
stage-scoped flag death). niubash gate slice run-execscript: the
x1..x3b family now matches exec.right; remaining diffs are the
already-tracked E2BIG/#3712, exec -a prolog, coproc and job-control
noise. tests/issue3605_pipeline_async_stdin.rs pins the four shapes
(4 tests).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(tests): quote fixture path in pipe-stdin pins for Windows (Refs #3605)

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant