Skip to content

fix(#802/#804): interactive line-editor carrier panic + GNU rbash restricted-mode direction semantics - #823

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix/802-804
Oct 18, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix/802-804

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Two tickets, two commits, one PR. GNU oracle = WSL GNU bash 5.3.0 stdin/script method (/tmp/rbin/rbash -> bash-5.3 argv0 face and bash -r, both faces probed cell-by-cell). Vendored bash anchors are file:line citations only - no C mirrored or translated.

#802 - interactive line-editor path panics debug builds (COMPOUND_ASSIGNMENT_MARKER debug_assert)

Typing declare -A name=( + [中国]="北京" + ) line by line into an interactive debug build panicked at src/locale.rs's COMPOUND_ASSIGNMENT_MARKER debug_assert.

Root cause. The marker entry-point inventory (which boundaries may deliver carrier text to the sanctioned transport-to-visible decoder) covered exec/script/-c - all of which consume the marker at the assignment/word boundary before any display - but missed the host AST-inspection boundary: the interactive REPL decodes every AST word BETWEEN parse and execution (easter-egg routing, this-shell dispatch, positional params in the host's decoded_words), and the parser tags compound-assignment words with __RUBASH_CA1__ at parse time. Pre-execution transport text therefore legitimately reaches the decoder with the marker still aboard.

Fix. Audited the CA1 entries with the #729 carrier consumer inventory methodology: the exec/script/-c display paths were already guarded (assignment dispatch, xtrace word stripping, bad-substitution display); for the host AST-inspection boundary the decoder now consumes the marker (a _-gated prefix probe, free for marker-free words) instead of asserting it away. The marker registry's decode-boundary table documents the new entry. Lookalikes (__RUBASH_CA1_nearly__) and marker-free text stay byte-identical; marker_leak_golden (executor output) stays green. E2E: the three-line typed repro through the host ConPTY/raw-console leg no longer panics a debug build.

#804 - rbash restricted mode: three GNU divergences

Matrix cells (GNU 5.3.0 vs pre-fix rubash, -r and rbash argv0 faces agreed):

# form GNU rbash 5.3.0 (oracle) rubash before rubash after
11 echo hi > out (relative target) rc 1, out: restricted: cannot redirect output rc 0, ran rc 1, same diagnostic
11 > >> <> >& >| &> &>> 2> (any target incl. /dev/null) refused, <target>: restricted: cannot redirect output, rc 1 allowed unless target contained / refused, byte-identical message + rc
12 cat < file / 2< file / exec 3< file / <&0 allowed (read-only input is not in WRITE_REDIRECT) refused with the output diagnostic (slash targets) allowed
12 cat < missing <missing>: No such file or directory, rc 1 restricted: cannot redirect output OS error class, no "restricted" wording
13 command /bin/echo hi rc 1, /bin/echo: restricted: cannot specify `/' in command names rc 0, ran refused, byte-identical
13' command echo -p runs echo with -p (prints -p, rc 0) refused as command: -p: restricted runs, prints -p
13' command -v /bin/echo describes, rc 0 described described (unchanged)
13' command -- /bin/echo hi refused on the operand ran refused, byte-identical
11' { ...; } > f / ( ... ) > f / if..fi > f / for..done > f / case..esac > f / function > f / pipeline member > f / exec > f / 3> f refused, no file created ran and/or created f refused, no file, body skipped, rc 1
11' echo hi {v}> f v: restricted: ... (the variable, redir.c:137-138) ran v: restricted: ...
11' echo hi > $(echo f) literal $(echo f) in the message (redir.c:186-190) ran literal $(echo f)
11' echo hi 2>& f f: ambiguous redirect (not restricted) ran f: ambiguous redirect
11' >&N / <&N / <<< / heredocs allowed allowed allowed (unchanged)
lock set +r set: +r: invalid option + usage, still restricted same same (untouched)

Anchors: command.h:57 WRITE_REDIRECT(ri) over redir.c:919-924 (refuse after expansion, before open), redir.c:210 (message), redir.c:137-138/186-190 (message word rules), execute_cmd.c:5789 (command-name '/' scan - where command's operand lands via the pseudo-reserved prefix unwrap), execute_cmd.c:5606 (compound redirects precede the body), command.def:68-141.

Engine changes. The apply-time redirect gate (the do_redirections equivalent) refuses the WRITE_REDIRECT directions at GNU's exact position, so refusals order-route with the other redirect diagnostics; restricted_command_error drops the slash heuristic for directions and gains the option-position-aware command operand scan; the compound wrappers (brace group / subshell / if / for / loop / case) refuse before their entry-time target creation so no file materializes and the body is skipped with status 1; a refused pipeline member is skipped by the stream-routing walk (it used to reopen the refused target after the refusal). -r and rbash faces remain two spellings of one state; set +r stays locked.

Verification

  • New regressions: tests/issue804_restricted_redirect_command_regressions.rs (8 cases, one per matrix row family, both faces) and the declare -A name=(...) through the line-editor path panics in debug builds: COMPOUND_ASSIGNMENT_MARKER debug_assert (locale.rs) #802 decoder units + host-shaped AST walk in tests/decode_to_visible_text.rs.
  • Full suite, --no-fail-fast --test-threads=1, base 8ab35e8 vs this branch, bidirectional comm of the failure sets: zero new failures on the branch. The base-only extras are fresh-worktree artifacts (generated examples/, uninitialized third_party/bash submodule tests) and pre-existing signal/spawn environment flakes present in both sets (xtrace_carries_no_markers included - it is the PARAM_WORD_BACKSLASH_GUARD sibling assert family, failing identically on base).
  • cargo fmt --check clean.

…e line-editor boundary (#802)

Typing `declare -A name=(` / `[中国]="北京"` / `)` line by line into an
interactive debug build panicked the engine at the
COMPOUND_ASSIGNMENT_MARKER debug_assert in locale.rs: the host REPL
decodes every AST word BETWEEN parse and execution (easter-egg routing,
this-shell dispatch, positional params - niubash shell.rs
decoded_words), and the parser tags compound-assignment words with the
__RUBASH_CA1__ named-string carrier at parse time. The marker
entry-point inventory (which boundaries may deliver carrier text to the
sanctioned transport-to-visible decoder) listed the exec/script/-c
paths - all of which consume the marker at the assignment/word boundary
before any display - but missed the host AST-inspection boundary.

Audit (the #729 carrier consumer inventory methodology, applied to this
one marker):

- exec / script stdin / -c display paths: assignment values and xtrace
  words are CA1-stripped at the assignment dispatch, word-visibility and
  bad-substitution boundaries before decode (assignment_dispatch.rs,
  command_words.rs, execution_misc.rs, ast_print.rs) - guarded, no
  change.
- host AST inspection on the interactive line-editor path: the marker
  is transport by contract at this point, so decode_to_visible_text now
  consumes it (a `_`-gated prefix probe - free for marker-free words)
  instead of asserting it away; the golden assertion for this one
  marker is retired and the marker registry's decode-boundary entry
  table documents the boundary.

Regressions: the decoder keeps every non-carrier lookalike
(`__RUBASH_CA1_nearly__`) and mid-word/marker-free text byte-identical,
and the host-shaped AST word walk (tokenize + parse + decode each word)
is pinned alongside the raw-decoder units.

E2E: the three-line typed repro through the host ConPTY leg (raw
console readline) no longer panics a debug build and lands back at the
prompt; the marker-free output of echo/declare/xtrace is unchanged
(marker_leak_golden stays green).

GPL note: semantics anchored to the transport protocol contract, no C
source mirrored.
…d operands pass the '/' scan (#804)

Three cells of the niubash#413 GNU-rbash differential matrix diverged
(WSL GNU 5.3.0 rbash oracle, both the -r flag and the rbash argv0
face):

- 11: `>` `>>` `<>` `>&` `>|` (&> &>> 2> N>) ran instead of being
  refused - rubash gated on a SLASH IN THE TARGET, so every slash-free
  target slipped through.
- 12: `cat < /etc/hostname` was refused with the OUTPUT diagnostic -
  the direction test was inverted; GNU only restricts the
  WRITE_REDIRECT set (command.h:57 over redir.c:919) and read-only
  input stays allowed.
- 13: `command /bin/echo hi` bypassed the '/' scan - GNU strips the
  `command` prefix and dispatches the operand as the command, so the
  operand lands in execute_disk_command's restricted name check
  (execute_cmd.c:5789); -p stays refused (command.def:97-103) while
  -v/-V take the describe path and never execute.

Engine changes, all anchored to the vendored bash semantics (no C
mirrored):

- The apply-time redirect gate (reject_invalid_redirects, the
  do_redirections equivalent) refuses the WRITE_REDIRECT kinds after
  each operand's expansion and ambiguity checks and before the open -
  GNU's exact position (redir.c:919-924), so refusals order-route like
  every other redirect diagnostic and `<>` never creates. The
  `>&word` err_and_out translation is refused at its resolution point;
  `>&N`/`>&-` dups stay allowed. `{var}>` spellings report under the
  VARIABLE name (redir.c:137-138), command-substitution targets report
  the literal word (redir.c:186-190), everything else the expanded
  filename (redir.c:210).
- restricted_command_error drops the slash-in-target heuristic for
  directions and gains the `command` operand scan (option-position
  aware: `command echo -p` now runs echo with `-p` like GNU instead of
  refusing).
- The compound wrappers (brace group, subshell, if, for, loop, case)
  refuse before their redirect application, so `{ ...; } > f` no
  longer materializes `f` via the entry-time target creation before
  the leaf gate could speak - GNU leaves no file and skips the body
  with status 1. A refused pipeline member is likewise skipped by the
  stream-routing walk, which used to reopen the refused target after
  the fact.
- `-r` flag and rbash argv0 faces stay two spellings of one state and
  the `set +r` lock is untouched (`set: +r: invalid option` + usage,
  next redirect still refused - byte-verified against the oracle).

Differential regressions land per matrix row: write forms refused on
absolute/relative//dev/null targets with GNU's rc and message shapes,
read-only input allowed (file, fd 3, `<&0`, comsub), restriction
ordered inside the redirect list, pipeline members + fd-var + dup-word
+ comsub message shapes, and the face-equivalence cells.

GPL note: semantic contract and behavior tests only - no C translated
or mirrored.

@caomengxuan666 caomengxuan666 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

独立代码评审:REQUEST-CHANGES

评审基线:WSL GNU bash 5.3.0(1)-release rbash oracle;cr-823 @ 78d072b 独立 worktree,debug 构建自测。

F1(阻塞):{v}> 写方向仍物化目标文件,且截断已有内容

rubash -r -c 'echo hi {v}> f.txt' → 消息/rc 与 GNU 一致(v: restricted: cannot redirect output,rc 1),但 f.txt 被创建;已存在的 f.txt(内容 ORIGINAL\n)被截断为 0 字节。GNU oracle 同形:文件不存在、已有内容不动(9 字节保持)。变体 {v}>> {v}<> {v}>| 全部复现;exec {v}>、exec 3> 正常不物化。

  • 根因:apply_dynamic_fd_var_redirects(src/executor/command_execute.rs:337)在 reject_invalid_redirects 的 fd_var 拒绝臂(src/executor/redirection.rs:342-357)之前执行,execute_dynamic_fd_var_redirect(src/executor/trap_exec.rs:3042)在那里真实创建/截断目标;trap 路径(src/executor/trap_exec.rs:1762)同样先应用后 gate。GNU 的 restricted 检查(redir.c:919)先于 redir_varassign,故无副作用。
  • commit 承诺 "<> never creates, > never truncates" 在 fd_var 拼写上不成立,违背本修复"不物化文件"的关键验收;截断是数据破坏性副作用。
  • tests/issue804_restricted_redirect_command_regressions.rs:359-366(fd_var case)只钉消息文本,建议补文件不存在断言。

F2(minor):管道成员的拒绝消息不走 GNU 的 order-routing

  • (a) echo hi > $unsetv | cat:rubash 输出 : restricted: cannot redirect output(空词 + 错误类别),GNU 输出 $unsetv: ambiguous redirect。平路 rubash 正确(gate 的歧义检查先于 restricted 臂);管道 stage 相反——restricted 预扫描(src/executor/pipeline_exec.rs:2992)先于 reject_invalid_redirects(:3016),且预扫描的 redirect 循环不做歧义检查。
  • (b) echo hi 2>&1 >& pf.txt | cat:GNU 把拒绝消息经已应用的 2>&1 路由进管道(出现在管道 stdout),rubash 直接落 stderr(refused stage 整体跳过 route_pipeline_stage_streams,src/executor/pipeline_exec.rs:812-824)。
  • 两例均无文件物化(两端一致)。建议 stage 路径的拒绝消息统一走 reject_invalid_redirects 的顺序路由,预扫描只负责 fast-path 分流不产消息。

F3(nit):tests/decode_to_visible_text.rs:80

assert_eq!(decode_to_visible_text("x="), "x=") 是 marker-free 恒等断言,与第 75 行注释声称的 x=__RUBASH_CA1__ 存空值不对应。实测 decode_to_visible_text("x=__RUBASH_CA1__") == "x=" 成立,改断言即可钉住该注释。

F4(info):_ 前缀门控零开销为分析性结论

每字符一次 ch == '_' 比较;仅 _ 前缀做 Chars::clone + ≤13 字符探测,无分配。仓内无 decode_to_visible_text bench,#604 预算面无量化回归证据——风险可忽略,但"零开销"目前无测量背书。


已验证通过(自测证据)

  • #802:lookalike(__RUBASH_CA1_nearly__)、截断(__RUBASH_CA1_)、单前导 _RUBASH_CA1__、___RUBASH_CA1__、纯下划线、CJK 全部逐字节不变;用户可达文本受 pair-encoding 保护(echo __RUBASH_CA1__ 原样输出,rc 0),reserved 消费只作用于 parser 自打的 transport 载体;named_string_markers_test.sh 绿;入口表已记录(src/executor/markers.rs:29)。host ConPTY E2E 本仓不可复现(host 在 niubash 侧),host-shaped 单测(tokenize+parse+逐词 decode)为钉住代理。
  • #804 GNU 差分(5.3.0 oracle,-r 与 argv0 双 face 一致):> >> <> >| &> &>> 2> 2>>(5.3 确实拒 2>,与 WRITE_REDIRECT 5.3 扩展面一致){ ...; } > exec > exec 3> > /dev/null 全拒且无文件残留(compound/subshell/if/for/while/case/pipeline 七形态逐一验证不物化);cat <、exec 3<、<&0、>&2、>&- 放行;>&word/>& $v 在翻译点拒绝、>&N dup 放行;command /bin/echo 拒、command -v 描述、command -- 尾随拒绝、command echo -p 按 GNU 执行输出 -p、command -p 拒(消息逐字对齐);set +r 锁形状(invalid option + usage + 后续仍拒)逐字对齐。
  • 回归:issue804 8/8、decode_to_visible_text 4/4;全量 --no-fail-fast(PR 5398 pass/46 fail,8ab35e89 基线 5370/47)sequential 逐 suite 双向对比失败集一致——cli_tests 的 examples::*(10)+c_command_retires(1) 即已知 fresh-worktree 生成物缺失 11 项,与 fd_redirects::c_external(9)+tilde_user(3)、upstream_suite_slice_snapshots、windows_listing_cache(lib,flaky)、issue387/440 coproc-sigint(负载 flake,两端单独重跑均绿)全部两端同败;PR 新增测试全绿(regression suite 73 pass vs 基线 69)。
  • 红线:cargo fmt --check 干净;新增内容无 GPL 文本、无 C 镜像(command.h:57 / redir.c:919/210/137-138 / execute_cmd.c:5606/5789 / command.def:97-103 均为注释级语义锚点);2 commits 主题纯净无夹带;评审全程未改动仓内跟踪文件,临时 worktree 已清理。

…ures keep GNU order and stream routing (#804 review)

CR round on PR #823:

- F1: `{v}>` `{v}>>` `{v}<>` `{v}>|` still materialized the target - the
  dynamic fd-var applier opened/created the file (and truncated a
  pre-existing one to zero) before any restricted refusal, on the
  simple-command preflight and the exec builtin's with-operand site
  alike. The refusal now runs at the top of the applier, before
  redir_varassign, matching GNU's check-before-varassign order; the
  diagnostic routes through the redirects BEFORE the offending entry
  (issue #250 semantics), so `2>/dev/null {v}> f` stays silent. `{v}<`
  input and `{v}>&N` dups stay allowed.
- F2: a pipeline member's redirect failures now come from the ordered
  gate BEFORE the restricted scan, so ambiguity beats the restricted
  refusal on the same entry (redir.c:914 precedes :919 -
  `echo hi > $unsetv | cat` reports `ambiguous redirect`) and a refusal
  after an applied `2>&1` rides the dup into the pipe (`2>&1 >& f`
  reports into the consumer's stdin, stderr clean). Neither case
  materializes.
- F3: the decoder regression now pins the actual leading-carrier word
  shape (`x=__RUBASH_CA1__` decodes to `x=`) instead of an unrelated
  identity assertion.

Regressions: fd-var zero-materialization matrix (four write spellings x
simple/exec-stdio-only/exec-with-operand/pipeline-member paths, seeded
content unchanged + fresh target absent + `{v}<` allowed) and the
member order/routing cells (ambiguous-first, dup-into-pipe, no
materialization).
@caomengxuan666

Copy link
Copy Markdown
Member Author

Fix round pushed (43c1a13), all three findings addressed:

F1 (blocking) — fd-var zero-materialization. The refusal now runs at the TOP of apply_dynamic_fd_var_redirects (trap_exec), before redir_varassign touches anything — one choke point covering all four applier call sites (simple-command preflight command_execute:337, command_prepare:295/645, exec-with-operand trap_exec:1762). GNU's order (restricted check precedes the varassign arm, redir.c:919) restored: {v}> {v}>> {v}<> {v}>\| refuse with no file created and a pre-existing target's bytes unchanged; exec {v}> (stdio-only) and exec cat {v}> (with-operand) both covered; {v}< input and {v}>&N dups stay allowed. The diagnostic routes through the redirects BEFORE the offending entry (issue #250 machinery), so 2>/dev/null {v}> f is silent like GNU. The gate's fd-var arm remains as backstop.

F2 — member order/routing. The ordered gate now runs BEFORE the restricted scan in the sequential pipeline stage (GNU: do_redirections at execute_cmd.c:5606 precedes the builtin; per-entry ambiguity at redir.c:914 precedes :919). Verified against the oracle: echo hi > $unsetv \| cat → $unsetv: ambiguous redirect on stderr, no restricted wording, rc 0 (consumer's); echo hi 2>&1 >& f \| cat → the refusal rides the dup INTO THE PIPE (cat's stdin), stderr clean, no file — both byte-shaped like GNU 5.3.0. The scan now only speaks for the command-NAME forms the gate cannot see.

F3 — test assertion. The decoder unit now pins the real leading-carrier word shape: decode_to_visible_text("x=__RUBASH_CA1__") == "x=" (mirroring master's assignment-boundary reserved stance where x=__RUBASH_CA1__ stores an empty value), keeping the lookalike and mid-word cases.

New regressions: fd_var_write_spellings_never_materialize_the_target (4 write spellings × simple/exec-stdio-only/exec-with-operand/pipeline-member, seeded-content-unchanged + fresh-target-absent + {v}< allowed) and pipeline_member_redirect_failures_keep_gnu_order_and_routing (ambiguous-first, dup-into-pipe, no materialization). Full suite re-run (--no-fail-fast --test-threads=1, base 8ab35e8 vs this branch): bidirectional comm clean — zero new failures; base-only extras remain the 11 fresh-worktree artifacts (generated examples/, uninitialized bash submodule tests).

@caomengxuan666 caomengxuan666 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复核轮(43c1a132):REQUEST-CHANGES —— F1/F2/F3 修复本体确认有效,但同验收类新增两处泄漏

复核方式:WSL GNU 5.3.0 rbash oracle 逐 cell 对照 + cr-823 @ 43c1a13 独立 worktree debug 构建自测。

已确认修复

  • F1 本体:reject_restricted_fd_var_redirects(src/executor/redirection.rs:221-255)置于 applier 顶部(src/executor/trap_exec.rs:2887-2893),单点覆盖 apply_dynamic_fd_var_redirects 全部四个调用方。扩展矩阵 14 形态全过:while/for/until/case/subshell/if/group/exec(stdio-only)/exec(带操作数)/pipeline member/eval/trap/simple 的 {v}> {v}>> {v}<> {v}>| 均不物化、预置内容不变;{v}<、{v}>&N 放行。回归 fd_var_write_spellings_never_materialize_the_target 断言到位。
  • F2:gate 提前到 restricted 扫描之前(src/executor/pipeline_exec.rs:2992→3047 换位)。oracle 逐字节对齐:echo hi > $unsetv | cat 报 $unsetv: ambiguous redirect 无 restricted 字样 rc=0;echo hi 2>&1 >& f | cat 拒绝消息经 dup 进管道 stdout、stderr 干净、无物化。
  • F3:decode_to_visible_text("x=__RUBASH_CA1__") == "x=" 已钉住。
  • 新回归 10/10 + decode 5/5 全绿;全量 --no-fail-fast 5399 pass / 47 fail,失败集与 8ab35e8 环境基线同类(examples::*/c_external/tilde_user 等 fresh-worktree 生成物类 + coproc-sigint flake),issue804/decode 套件不在失败清单。fmt 干净、无 GPL/C 镜像、无夹带。

N1(阻塞):select 复合 wrapper 是 round-1 拒绝清单的漏网——物化文件 + 运行菜单 + 无诊断

round-1 的 restricted_compound_redirect_error 加到了 brace group/subshell/if/for/case,select 没有(src/executor/select_exec.rs 全文无 restricted 预检;loop_select.rs:264 只包了 for)。select 经 with_command_input_redirects(src/executor/select_exec.rs:142)→ command_input_scope.rs:62 的直接 execute_dynamic_fd_var_redirect 调用(绕过 applier 顶部预检)打开目标。

  • rubash -r:select x in a; do :; done > f.txt(纯 > 即漏,{v}>/{v}>>/{v}<> 同)→ stderr 打出 select 菜单(1) a、#? ),f.txt 被创建,无任何 restricted 诊断,rc 1;do echo BODY-RAN; break; 体可达。GNU oracle:f.txt: restricted: cannot redirect output,无菜单、无文件。
  • 建议:在 select_exec.rs 菜单/with_command_input_redirects 之前加与 for 相同的 wrapper 预检,并给 fd_var_write_spellings_never_materialize_the_target 补 select 行。

N2(同验收类):fd_var 预检不看来列表中更早的写方向——组合形态重新物化 + 静默吞诊断

预检在 command_execute.rs:337(先于 dispatch:30 的 gate)且只找第一个 fd_var 条目,于是:

  • echo hi > s1.txt {v}> s2.txt → rubash 报 v: restricted... 但 s1.txt 被物化(0 字节)——#250 前缀路由 write_redirect_diagnostic_at 会真实 open 更早的 > s1.txt(>> 同样,<> 前缀不打开)。GNU:先拒 s1.txt(s1.txt: restricted...)且零创建。对照:纯写组合 > a.txt > b.txt 两端一致(gate 顺序正确),只有 fd_var 组合分歧。
  • echo hi 2>/dev/null {v}> g.txt → rubash 完全静默 rc=1(消息路由进前缀 2>/dev/null);GNU 5.3 先拒 2>/dev/null 本身(/dev/null: restricted: cannot redirect output,可见)。commit message 的 "2>/dev/null {v}> f stays silent" 建模的是 ≤5.2 语义(2> 可成功应用),与自述的 5.3.0 oracle 相反——round-1 自己的 13-refusal 计数里 2> 也是被拒项。
  • 建议方向:预检改为对整张 redirect 列表的第一个 restricted-write 条目发言(或把 fd_var 拒绝挪到 gate 之后让列表顺序裁决),并钉住这两个组合 cell。

结论

三处原 findings 修复质量好、oracle 对齐;但 N1 与 N2 仍在"修复后 f 不得存在 + 诊断形状对齐 GNU"的验收面上。修掉这两处(各为小改动)即可 APPROVE。

…s at the first restricted-write entry (#804 review round 2)

CR round 2 on PR #823:

- N1: the select wrapper had no restricted pre-check — the loop's
  redirects reached the compound input binder (execute_dynamic_fd_var_redirect
  directly, then open_compound_output_redirects), so
  `select x in a; do :; done > f` printed the menu and materialized f
  where GNU refuses before the menu with no file. execute_select_command
  now runs the same compound pre-check as if/for/loop/case/subshell/brace,
  and with_command_input_redirects itself gained the entry-level
  pre-check as defense for every binder caller: the first restricted
  write refuses before anything opens or binds, body skipped, status 1.
- N2: the materialization pre-check scanned only for an fd-var entry, so
  `echo hi > s1.txt {v}> s2.txt` named the var while the issue-#250
  prefix routing still opened s1.txt (zero bytes), and
  `2>/dev/null {v}> g.txt` stayed silent. It now speaks at the FIRST
  restricted-write entry of the whole ordered list — GNU 5.3 refuses an
  earlier plain write (s1.txt named, nothing materialized) and refuses
  the `2>/dev/null` entry itself (`/dev/null: restricted: cannot
  redirect output`) instead of modeling pre-5.3 silence.

Regressions: select refusal cells (plain + fd-var, menu-free and
file-free) and the combination cells (first-entry naming, append
variant, /dev/null-entry refusal — all with zero-materialization
assertions). Oracle: WSL GNU bash 5.3.0 rbash, all five new cells
byte-shaped identical.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Round 2 pushed (2c056d6):

N1 — select. execute_select_command now runs the same compound pre-check as the other wrappers, AND with_command_input_redirects itself gained the entry-level pre-check as defense at the binder every wrapper funnels through (it reaches execute_dynamic_fd_var_redirect directly and opens the compound's output targets). Verified: select x in a; do :; done > f and ... {v}> f → rc 1, the GNU diagnostic, no menu, no file — byte-shaped identical to the 5.3.0 oracle.

N2 — first restricted-write entry. The materialization pre-check now scans the WHOLE ordered list and speaks at the first restricted-write entry (fd-var or plain), per the GNU 5.3 semantics you called out:

  • echo hi > s1.txt {v}> s2.txt → s1.txt: restricted: cannot redirect output, neither file materialized (the prefix routing that used to open s1.txt never runs — we speak AT s1's entry).
  • echo hi >> s1.txt {v}> s2.txt → same.
  • echo hi 2>/dev/null {v}> g.txt → /dev/null: restricted: cannot redirect output — the 2>/dev/null entry is itself the refusal, nothing silent (oracle-confirmed against 5.3.0; the ≤5.2 silent modeling is gone).

New regressions: select_loop_refuses_before_menu_or_materialization (plain + fd-var, menu-free/file-free) and fd_var_refusal_speaks_at_the_first_restricted_write_entry (first-entry naming, append variant, /dev/null-entry refusal — all with zero-materialization assertions). Suite re-run (--no-fail-fast --test-threads=1 vs base 8ab35e8): bidirectional comm clean, zero new failures. All five new oracle cells (select ×2, combination ×3) verified byte-identical against WSL GNU bash 5.3.0 rbash.

@caomengxuan666 caomengxuan666 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复核轮 3(2c056d6e):REQUEST-CHANGES —— N1 修复确认;N2 首入口选择正确,但缺"歧义先于 restricted",并把 round-1 已对齐的一格改退了

WSL GNU 5.3.0 rbash oracle 逐格对照 + cr-823 @ 2c056d6 独立 worktree debug 自测。

N1:确认修复 ✅

  • execute_select_command 补了与 if/for/case/subshell/brace 同款 wrapper 预检(src/executor/select_exec.rs:14-25);防御纵深 reject_restricted_write_redirect_entry 落在 binder 顶部(src/executor/command_input_scope.rs:55-65),返回 T::default() 跳过体。
  • (a) 覆盖性:with_command_input_redirects 现有 9 个调用方(alias_loops.rs:100、compound_exec.rs:1407/1440/1638/2673、loop_select.rs:298、pipeline_exec.rs:347、select_exec.rs:155、builtins/source/simple_if.rs:78)全部经 binder 预检;直连 execute_dynamic_fd_var_redirect 的调用点共三处——command_input_scope.rs:72(在 binder 预检之后✅)、trap_exec.rs:2917(applier 顶部预检之后✅)、trap_exec.rs:2192(exec 列表序 applier,上游 gate 先行 shield,exec {v}> 探针无物化✅)。没有第七个绕过点。
  • (b) 自跑:select x in a; do :; done > f.txt → rc 1、无菜单、无文件、f.txt: restricted: cannot redirect output;{v}> 拼写报 v: restricted... 同样干净;BODY-RAN 体不可达。与 GNU 逐字节同形。

N2:首入口选择正确,但入选条目自身缺歧义先决(redir.c:911-914 先于 :919)→ 一处回归 + 一处历史遗留

五格修复本体确认:> s1.txt {v}> s2.txt 报 s1.txt: restricted... 且双双未物化(含 >> 变体);2>/dev/null {v}> g.txt 报 /dev/null: restricted...(按 5.3 语义拒该入口本身)。但预检在入选的 write 条目上直接说 restricted,没有先解该条目自己的歧义:

  • 回归(round-1 曾正确):rubash -r -c 'echo hi > $unsetv' —— round-1/2 经 gate 报 $unsetv: ambiguous redirect(GNU 一致);现在 applier 预检(command_execute.rs:337 先于 dispatch:30 gate)抢答 : restricted: cannot redirect output(空词 + 错类别)。GNU:$unsetv: ambiguous redirect。
  • echo hi > $unsetv {v}> s2.txt → rubash : restricted... vs GNU $unsetv: ambiguous redirect。
  • v="a b"; echo hi > $v → rubash a b: restricted... vs GNU $v: ambiguous redirect(GNU 报 raw 词)。
  • echo hi {v}> $unset2 → rubash v: restricted... vs GNU v: ambiguous redirect(fd_var 歧义按变量名报)。
  • 复合 wrapper 路径同病(round-1 起即错,本轮未变):while :; do :; break; done > $unsetv → rubash : restricted... vs GNU $unsetv: ambiguous redirect(restricted_compound_redirect_error 的两个臂同样歧义盲)。
  • 对照确认无回归的格子:exec > $unsetv(gate 先行)与 exec cat > $unsetv 都仍报 ambiguous ✓;管道格(gate 先行)✓;> s3.txt > $unsetv 首入口 restricted ✓ 两端一致。

建议:reject_restricted_write_redirect_entry 与 restricted_compound_redirect_error 在对入选条目说 restricted 之前,先做与 gate 相同的歧义解析(零字段无引号 span / 多字段 → 报 {raw}: ambiguous redirect;fd_var 按 oracle 报 v: ambiguous redirect),restricted 措辞只在歧义通过后说。并钉住 simple 路径格 echo hi > $unsetv → $unsetv: ambiguous redirect(它 round-1 正确、本轮退化且无测试钉住——现存歧义钉只有管道格与 2>& dup 格)。

附带记录核实

select 非 restricted 在 stdin EOF 的 rc:oracle 实测 GNU 5.3.0 也是 rc=1(bash -c 'select x in a; do :; done' </dev/null → 1),rubash 同为 1——PR 描述里"GNU rc=0"的前提不成立,两端一致,无需处理。✅

其余

  • 新回归 12/12 全绿(fd_var_refusal_speaks_at_the_first_restricted_write_entry、select_loop_refuses_before_menu_or_materialization);全量 --no-fail-fast 5403 pass / 45 fail,失败集仍为 8ab35e8 环境基线同类(examples/c_external/tilde_user/coproc-flake 等),issue804/decode 不在失败清单。
  • fmt 干净、无 GPL/C 镜像、单 commit 无夹带;评审未改仓内文件。

结论

N1 关闭。剩一个精确小修:入选条目歧义先决(两个函数 + 补钉 simple 格)。修掉即可 APPROVE。

…al at every refusal site (#804 review round 3)

The materialization pre-check and the compound wrapper scan spoke their
restricted wording for an entry whose own ambiguity had not been
resolved: `echo hi > $unsetv` (the plain simple-command cell) answered
`: restricted: cannot redirect output` — empty word, wrong class —
where GNU reports `$unsetv: ambiguous redirect` (redir.c:911-914
precede :919 on the same entry). The compound wrapper path had been
ambiguity-blind the same way since round 1 (`while ... > $unsetv`).

All three refusal sites now share one per-entry diagnostic
(restricted_write_entry_diagnostic) that mirrors the ordered gate's
resolution: zero fields without an anchored quoted span or a multi-field
expansion reports `{raw}: ambiguous redirect` (a varassign entry under
the VARIABLE name, redir.c:137-138 — `{v}> $unset2` reports
`v: ambiguous redirect`); an anchored quoted-empty field still refuses
restricted (`: restricted: cannot redirect output`, oracle-confirmed
against GNU 5.3.0) before any open. The pipeline stdio routing walk —
which can probe before the gate — stays silent for restricted-write
entries and skips them, so each failure speaks exactly once with the
entry's own class (the walk's bare ambiguity used to double-report a
pipeline fd-var cell).

Regressions: the flagged simple cell, the raw-word multi-field cell, the
varassign-ambiguity cell, ambiguity-first over a later restricted entry
(simple + compound wrapper), the first-entry-restricted cell, and
pipeline single-message cells — all with no-restricted-wording and
no-materialization assertions.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Round 3 pushed (ad9970c):

Ambiguity before restricted, everywhere. All three refusal sites now share one per-entry diagnostic (restricted_write_entry_diagnostic) that mirrors the ordered gate's resolution before any restricted wording:

  • zero fields without an anchored quoted span, or multi-field expansion → {raw}: ambiguous redirect (a varassign entry under the VARIABLE name, redir.c:137-138) — so {v}> $unset2 reports v: ambiguous redirect;
  • an anchored quoted-empty field still refuses restricted (: restricted: cannot redirect output, open never happens) — oracle-confirmed against GNU 5.3.0.

Sites converted: the materialization pre-check (which used to pre-empt the gate and misreport the flagged simple cell echo hi > $unsetv), the compound wrapper scan (ambiguity-blind since round 1 — while ... > $unsetv now reports the ambiguity), and the ordered gate's fd-var arm.

Plus one the review hadn't surfaced yet: the pipeline stdio routing walk (apply_ordered_output_redirects) probes BEFORE the gate and spoke its own bare ambiguity for restricted-write entries — {v}> $unset2 \| cat double-reported ($unset2: from the walk, then v: from the binder pre-check). The walk now stays silent for restricted-write entries and skips them (no open, no state record); each failure speaks exactly once with the entry's own class.

New regressions (ambiguity_precedes_the_restricted_refusal_everywhere): the flagged simple cell, the raw-word multi-field cell (v="a b"; > $v → $v: ambiguous redirect), the varassign-ambiguity cell, ambiguity-first over a later restricted entry (simple + compound wrapper), the first-entry-restricted cell, and pipeline single-message cells — all asserting no-restricted-wording and no materialization. Suite re-run (--no-fail-fast --test-threads=1 vs base 8ab35e8): bidirectional comm clean, zero new failures. All round-3 oracle cells byte-identical against WSL GNU bash 5.3.0 rbash.

@caomengxuan666 caomengxuan666 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复核轮 4(ad9970ca):APPROVE

WSL GNU 5.3.0 rbash oracle 逐格对照 + cr-823 @ ad9970c 独立 worktree debug 自测。

① 共享诊断与 gate 逐入口顺序一致 ✅

restricted_write_entry_diagnostic(src/executor/redirection.rs:168-249)严格复刻 gate 逐入口解析:零字段无锚定引号 span 或多字段 → {raw}: ambiguous redirect(varassign 按变量名,redir.c:137-138);锚定引号空字段仍 restricted(空文件名名址,oracle 逐字节确认);restricted 词规则(comsub 字面/展开目标/变量名)不变。三个拒绝点(物化预检 :266、compound wrapper 扫描 :157、gate fd_var 臂 :403)全部改用共享诊断。其余两处内联 restricted 文案语义等价:>&word 翻译点(redirection.rs:601,歧义在其所在 dup 臂内已先解)与 gate 平路臂(redirection.rs:666,位于自身歧义检查之后)。

三形态对照(rubash vs GNU 5.3.0,逐字节同形,仅仓级既有 bash:/rbash: 前缀差异):

  • echo hi > $unsetv → $unsetv: ambiguous redirect(round-3 退化的 simple 格已恢复)✅
  • v="a b"; > $v → $v: ambiguous redirect(raw 词)✅
  • echo hi {v}> $unset2 → v: ambiguous redirect(变量名)✅
  • echo hi > "" {v}> q.txt → : restricted: cannot redirect output、q 不存在 ✅

② 双报告消除 ✅

echo hi {v}> $unset2 | cat:恰一次发言(stderr 1 行 v: ambiguous redirect)、stdout 干净、rc 0——与 GNU 逐字节同形。routing walk 对 restricted-write 条目静默跳过(apply_ordered_output_redirects,redirection.rs:1118-1129),非受限路径不受影响(skip 以 restricted 选项为门)。

③ 十格矩阵自跑(全过,含点名的两格)✅

simple 歧义格、multi-field 格、fd_var 歧义格、锚定引号空格、2>/dev/null {v}> 格、> s1 {v}> s2 首入口格、wrapper 歧义格(while ... > $unsetv → $unsetv: ambiguous redirect)、双报告格、> s3.txt > $unsetv 首入口 restricted 格(s3.txt: restricted...,无物化)、管道 fd_var 单消息格——全部与 GNU 同形,全部零物化。

④ 新回归质量 ✅

ambiguity_precedes_the_restricted_refusal_everywhere:钉住 round-3 点名的 simple 格(含无 restricted 字样 + rc 1 断言)、multi-field raw 词、varassign 变量名、歧义先于后置 restricted(simple + compound wrapper 双路径,含后置目标不物化断言)、首入口 restricted 保 verdict、管道单消息格。套件 13/13 + decode 5/5 全绿。

⑤ 红线 ✅

cargo fmt --check 干净;新增无 GPL 文本/C 镜像;单 commit 仅 redirection.rs + 回归测试,无夹带;全量 --no-fail-fast 5406 pass / 43 fail,失败集仍为 8ab35e8 环境基线同类(examples/c_external/tilde_user/coproc-flake 等),issue804/decode 不在失败清单。评审未改仓内跟踪文件,worktree 已清理。

结论

APPROVE。四个 review 轮的全部 findings(F1 fd_var 物化、F2 管道路由、F3 断言、N1 select、N2 歧义先决、双报告)均已修复且 oracle 对齐;reviewer 侧无非阻塞遗留。

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