Repository navigation
fix(executor): admit Mach-O images in the exec gates on macOS (Refs #3585) - #3586
Merged
Merged
Conversation
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿(逐项):
F 点:无。 |
Member
Author
|
【队长终裁】PASS 核过审计报告(6885829768)+ CI 全表。机制与 GNU 一致(shell_execve 用本地内核 execve;macOS 内核加载 Mach-O 不会走 ENOEXEC 脚本回退);魔数表 8 项与 <mach-o/loader.h>+<mach-o/fat.h> 一致;cfg(macos) 桩使非 macOS 目标行为逐字节不变。CI macOS lib 腿红集 {issue2875},与 Windows 腿差集 ∅;三红任务红名全为 issue2875 基线。无新钉——macOS 专属路径在 Windows/Linux 上无法钉,属观察项非 F 点;后续可在 macOS 腿上补钉,不拦合入。CONFLICTING——合入轮先 update-branch + 合并形重验(钉面为空,以 lib 双边 + |
caomengxuan666
marked this pull request as ready for review
November 15, 2026 02:05
Member
Author
caomengxuan666
force-pushed
the
devin/macos-macho-exec
branch
from
November 15, 2026 02:27
fba6f70 to
2616f08
Compare
This was referenced Nov 15, 2026
Merged
Merged
caomengxuan666
added a commit
that referenced
this pull request
Nov 16, 2026
…(Refs #3605) (#3671) * fix(builtins): wrap inline printf precision digits into the libc int field (Refs #3605) GNU hands `%.<digits>' verbatim to the host libc's printf(3) via the PF() macro (builtins/printf.def:152-175). On BSD/Darwin libc the precision digit run accumulates into an int field (xprintf.c:558-559), wrapping mod 2^32: `printf "%.9223372036854775825s" XY' prints XY, and the vendored printf.right golden expects exactly that. The previous EOVERFLOW+PRETURN model fits an inline field *width* (xprintf.c:604-625 feeds an INT_MAX-checked pad) but not precision. Precision overflow now wraps the digit run two's-complement into i32: positive results apply as precision, negative results are "as if it were missing". Inline width overflow keeps the EOVERFLOW error, and the printstr specs (b/q/Q/T/S/C/wide) keep GNU decodeint() erange semantics unchanged. Verified on macOS arm64 vs GNU bash 5.3.20: %.9223372036854775825s/d render as %.17s/%.17d, %.4294967295s prints the full string, and niubash run-printf is PASS (the only remaining diff is the Mach-O exec gap covered by PR #3586). New unit tests pin the wrap, the wrapped-negative case, and the width EOVERFLOW boundary. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(builtins): pin inline printf width/precision overflow EOVERFLOW (Refs #3605) Reverts the i32-wrap model for inline precision digits: on the glibc oracle (WSL GNU bash 5.3.20) both width and precision digit runs outside i32 fail the directive with EOVERFLOW, matching printf.def's PF() -> host libc printf(3) path. The BSD/Darwin wrap model is unverifiable here and is not the project oracle, so the product change is dropped; what remains is regression coverage asserting the verified verdict. --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
caomengxuan666
added a commit
that referenced
this pull request
Nov 17, 2026
* fix(builtins): wrap inline printf precision digits into the libc int field (Refs #3605) GNU hands `%.<digits>' verbatim to the host libc's printf(3) via the PF() macro (builtins/printf.def:152-175). On BSD/Darwin libc the precision digit run accumulates into an int field (xprintf.c:558-559), wrapping mod 2^32: `printf "%.9223372036854775825s" XY' prints XY, and the vendored printf.right golden expects exactly that. The previous EOVERFLOW+PRETURN model fits an inline field *width* (xprintf.c:604-625 feeds an INT_MAX-checked pad) but not precision. Precision overflow now wraps the digit run two's-complement into i32: positive results apply as precision, negative results are "as if it were missing". Inline width overflow keeps the EOVERFLOW error, and the printstr specs (b/q/Q/T/S/C/wide) keep GNU decodeint() erange semantics unchanged. Verified on macOS arm64 vs GNU bash 5.3.20: %.9223372036854775825s/d render as %.17s/%.17d, %.4294967295s prints the full string, and niubash run-printf is PASS (the only remaining diff is the Mach-O exec gap covered by PR #3586). New unit tests pin the wrap, the wrapped-negative case, and the width EOVERFLOW boundary. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * api: Session::run admits live expand_aliases with an empty table (Refs #3605) rubash#3605 class B (run-alias tail): Session::run's grouped-driver admission required a NON-EMPTY alias table on top of the live expand_aliases flag, so a submission like '-o posix -c' text — where shell.c:1853 init_noninteractive seeds expand_aliases before the reader starts but no aliases are defined yet — took the whole-source route. That route's word-level alias fallback expands reserved words without parse.y:5751-5769's posix ordering (posix checks reserved words BEFORE alias expansion), so 'alias for=echo\nal for foo in v\ndo ...' expanded 'for' to 'echo' and died on a syntax error where GNU runs the loop and prints 'foo=v bar='. GNU's reader is incremental (evalstring.c parse_and_execute) and the alias gate is consulted on every token (parse.y:5759), so aliases defined by an earlier line must be live for the lines read after it — the same admission main.rs computes as alias_live_at_start for the -c route (rubash#414). Drop the non-empty-table term: the flag is the whole admission, matching the bin-side answer. Verified: niu -o posix -c 'alias for=echo; al for foo in v; do echo foo=$foo bar=$bar; done' now prints 'foo=v bar=' (GNU bash 5.3.20 identical); niubash gate run-alias diff cleared (PASS). New session_api test pins the posix run over this contract; the pre-existing macOS-only build_run_and_state_views_round_trip /var -> /private/var canonicalization flake is unchanged. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * test(api): spell the posix-alias pin redirect with a relative path (Refs #3605) --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
Refs #3585
What
On macOS, rubash's two exec admission gates whitelist only
#!,\x7fELF, andMZ, so every Mach-O binary is classified as an ENOEXEC candidate and refused withcannot execute binary file(126). No external command can run at all on macOS — same on the released niubash v1.5.0 tarball.executor::path::is_macho_image()matching thin Mach-O (MH_MAGIC/MH_CIGAM, 32- and 64-bit, both byte orders) and fat/universal (FAT_MAGIC/FAT_CIGAM, both byte orders); cfg-gated, returnsfalseoff-macOS.program_execs_directly()andis_enoexec_candidate().GNU reference
execute_cmd.c:6126 shell_execve()callsexecve(2)directly and only falls back to script interpretation on ENOEXEC — the kernel, not the shell, decides what's loadable. On macOS that's Mach-O, not ELF.Verification (macOS 26.6.2 arm64, niubash built against this branch)
scripts/run-bash-upstream-with-niubash.sh): 0/86 → 30/86 (remainder: pre-existing semantic diffs + macOS harness gaps like missingrecho//dev/tty)cargo test --workspacefailing targets: ~30 → 15 (remainder: test portability, wave-2 unix signal items — same classes as CI)niu -cexternal commands, pipelines, PATH lookup, absolute paths all exec;./binaryas a script operand still correctly refused with 126cargo fmt --check -p rubashcleanDraft per workflow (first commit). Written by Devin