Repository navigation
execscript: ENOEXEC binary gate on every face - #3718
Merged
Merged
Conversation
…ry face
GNU execute_cmd.c:6139-6233 shell_execve classifies an ENOEXEC operand
by its first 80 bytes (general.c:739 check_binary_file: ELF magic, or
a NUL in the first line — two under '#!') BEFORE any fallback, and
refuses it via internal_error (execute_cmd.c:6228) with
EX_BINARY_FILE = 126. Three places diverged on macOS:
- is_enoexec_candidate treated \x7fELF as kernel-native everywhere;
Darwin's execve refuses ELF like any other non-Mach-O file, so a
corrupt ELF operand skipped classification and fell into libc's
silent /bin/sh spawn substitution — the binary's bytes ran as a
script ('./x: line 1: ELFgarbage: command not found', rc 127) where
GNU refuses: 'bash: line 1: ./x: cannot execute binary file: Exec
format error'. ELF is now a candidate unless execve accepts it
(non-Apple).
- exec_format_refusal's binary arm printed 'bash: <word>' bare;
GNU's internal_error report carries the command line and appends
strerror(ENOEXEC) — now error_prefix_for_line + 'cannot execute
binary file: Exec format error'.
- execute_direct_shell_script's read_to_string let a binary operand
surface as a UTF-8 decode error (or run as carrier-marked text); it
now applies check_binary_file on the first min(80, len) bytes and
reports the entry face's own diagnostic — '<file>: <file>:' for the
same-shell script child (bash already bound to the filename,
shell.c:1659-1692 open_shell_script), '<name>: line N: <word>: ...
Exec format error' for the ENOEXEC arm. Bytes that pass decode via
bytes_to_script_text (rubash#132), never a validity refusal.
Verified against GNU bash 5.3.20 on macOS arm64 (ELF operand line
1/line 2 shapes, NUL-in-first-line, MZ bytes keeping the script
fallback, plain text ENOEXEC still runs). 3 new pins in
tests/issue3605_enoexec_binary_gate.rs.
Refs #3605
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This was referenced Nov 15, 2026
Member
Author
|
【WIN-AGENT-AUDIT-u3】PR #3718 — 续作开工 发现与计划:
|
Member
Author
|
【WIN-AGENT-AUDIT】PR #3718 第1轮 — 建议:FAIL 机制核查:
腿:
F 点:
续作记录:
未跑/VOID 的腿:Windows 侧无法产生真 ENOEXEC(无 execve), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#3605execscript cluster: the ENOEXEC binary gate (check_binary_file,general.c:739) must classify an operand by its first 80 bytes before any fallback on every face — three places diverged on macOS, all verified against GNU bash 5.3.20 (/opt/homebrew/bin/bash).is_enoexec_candidatetreated\x7fELFas a kernel-native image everywhere. Darwin'sexecverefuses ELF with ENOEXEC like any other non-Mach-O file, so a corrupt ELF operand skipped classification and fell into libc's silent/bin/shspawn substitution — the binary's bytes ran as a script:ELF now stays a candidate unless the local kernel accepts it (
cfg!(not(target_vendor = "apple"))), so the existing classification refuses it.exec_format_refusal's binary arm printedbash: <word>bare; GNU'sinternal_errorreport (execute_cmd.c:6228) carries the command's line and appendsstrerror(ENOEXEC). Nowerror_prefix_for_line+cannot execute binary file: Exec format error— the prolog also honors the real shell name andgnu_errfmt.execute_direct_shell_scriptread the operand withfs::read_to_string, surfacing a binary as a UTF-8 decode error. It now appliescheck_binary_fileon the firstmin(80, len)bytes and reports the entry face's own diagnostic —<file>: <file>:for the same-shell script child ($0already bound to the filename,shell.c:1659-1692open_shell_script),<name>: line N: <word>: ... : Exec format errorfor the ENOEXEC arm. Bytes that pass the gate decode throughbytes_to_script_text(rubash#132), never a validity refusal.Pins (
tests/issue3605_enoexec_binary_gate.rs, 3 tests): ELF refused at line 1 and line 2, NUL-in-first-line refused, MZ bytes and plain#!-less text keeping the ENOEXEC script fallback — matching GNU's observed behavior for each.Companion niubash PR (operand prolog + harness
THIS_SHsymlink): unixwin/niubash#1023.Refs #3605