Repository navigation
fix(arith): trap top-level $ reads under set -u before expansion erases them (Refs #3251) - #3465
Conversation
…es them (#3251) GNU expand_arith_string (subst.c:3981, via execute_cmd.c:3936 / eval_arith_for_expr at :3171) traps an unbound $name read during expansion (subst.c:11023 unbound_variable: -> err_unboundvar), but this tree's embedded-parameter walk expands the read to empty without trapping, so the post-expansion nounset scan never saw the name and (( $undef )) went silent (rc 0). Scan the RAW expression before any expansion pass erases it, with the same param_expand rules as the #3199 subscript scan (first_unbound_dollar_read), and record the leftmost trap in the #3199 S2 slot the existing scan point consults first. Single-quoted spans inside subscripts are masked out first: they are literal keys there (b['$undef'] is an operand error, not nounset), while a single quote at the top level is data in arith text and the $ read inside it still traps. A plain $N positional renders with the $ (GNU subst.c:10500-10512 uerror), unlike braced ${N} (bare digit). Applies to the expanding entries only ((( )), $(( )), arith-for); let operands arrive already expanded, so a $name there stays evalexp data. GNU anchors: subst.c:3981 expand_arith_string, subst.c:11023-11027 unbound_variable, subst.c:10500-10512 positional uerror, expr.c:1190-1216 expr_streval, execute_cmd.c:3936/3171. Refs-only: #3251. UNVERIFIED-BY-CAPTAIN. 本 PR 删除了什么:无删除。仅新增算术 nounset 预扫描与 $N 诊断渲染修正;无公开 API、文档或行为删除。
…3251) The #3251 raw-text scan skipped every `$(...)` span, on the claim that each is a separate frame whose own machinery traps inside it. That holds for a `$(...)` command substitution (the subshell traps), but not for a nested `$((...))` arithmetic expansion: the enclosing expansion expands it inline (GNU subst.c:3981 expand_arith_string recurses into it), and no separate entry ever scans it — so `(( $(( $undef )) ))` went silent (rc 0) even after the first fix (probe c13). Recurse first_unbound_dollar_read_arith into the inner text of a `$((` span (re-masking first, so a quoted subscript key inside the nest stays literal); `$(...)` is still skipped. The doc comment's "separate frame" claim for `$((...))` is corrected with it. Regression nails: tests/issue3251_arith_dollar_nounset_bypass.rs, 32 tests (26 trap cells + 6 controls) over the lane's probe matrix (c01-c27/q01-q15/x01; c13/x01 exercise the recursion; c11 omitted, already nailed by the #3199 pin). GNU anchors: subst.c:3981/11023/ 10500-10512, execute_cmd.c:3171/3936, expr.c:1150. Verification this round: rustfmt --check clean on both touched files; marker-lint OK; utf8-boundary hygiene clean; GNU anchor line numbers re-verified. NOT run (environment-blocked, see REPORT.md §8-§9): nail double-sided, GNU three-way re-probe, full lib double-sided, RUSTFLAGS="-D warnings" cargo check — local write wall intermittent (EDQUOT), Simular box disk 100% with its shell channel down, old-server route with it, X299 direct not yet available. Deferred to the captain review round on X299. UNVERIFIED-BY-CAPTAIN. Refs-only: #3251. 本 PR 删除了什么:无删除。仅新增嵌套算术 扫描递归与 32 个回归钉;无公开 API、文档或行为删除。
|
Captain review — FAIL (rework needed) Verified the PR head 1. The nested-arith cell is still red. Against the lane's 32-test nail 2. The PR contains no regression nail. What passed on this head: hygiene trio all green on Owed on the reworked head (blocked this round by the local write wall, Rework: (1) push the c13 recursion fix, (2) add the 32-test nail file, |
|
Update: the rework requested in the review above has landed — head is now |
|
【WIN-AGENT-AUDIT】 PR #3465 第1轮 — 建议:PASS 机制核查:
腿(逐项):
F 点:无(队长前轮 F 点 c13 已消除)。 续作记录:未动代码。 未跑/VOID 的腿:
|
Pin only; the #3295 fix lane waits for PR #3465 to merge. Preserved as a draft per captain order so the pin is not held only in a local tree. UNVERIFIED-BY-CAPTAIN. Co-authored-by: 曹梦轩 <[email protected]>
根因
GNU
expand_arith_string(subst.c:3981,经 execute_cmd.c:3936 / eval_arith_for_expr :3171)在展开阶段即捕获未绑定的$name读数(subst.c:11023unbound_variable:→ err_unboundvar),但本仓的内嵌参数展开把该读数静默展为空,致使展开后的 nounset 扫描永远看不到名字,(( $undef ))在set -u下静默 rc 0。修法
在任何展开步骤抹除名字之前,先对原始表达式做一次$(subst.c:10500-10512 uerror),与 $ {N}`(裸数字)区分。
$" 读数预扫描,沿用 #3199 下标扫描的 param_expand 规则(first_unbound_dollar_read),把按文本顺序最左的陷阱记入 #3199 S2 槽,由既有扫描点优先上报。下标内的单引号段先掩掉:其内是字面 key(b['$undef']应为 operand error 而非 nounset),而顶层的单引号在算术文本里只是数据,其内的$" 读数仍应捕获。裸$N" 位置参数按 GNU 渲染带仅作用于展开型入口(
(( ))、$(( ))、arith-for);let" 操作数已展开,$name" 在其内仍是 evalexp 数据,不动。GNU 锚点
验证(进行中)
$(( ))框内陷阱(c13/p01/p02/s04-s07/d02-d05/x02,嵌入式纯求值器吞掉框内失败,续修中)与既有残留(c12let"、c14/c26:?`、q02 单引号下标键、s01 单引号裸名,待 base 对照确认是否既有)外,其余与 GNU 逐字一致。-D warnings、hygiene 待跑。UNVERIFIED-BY-CAPTAIN
本 PR 删除了什么
无删除。仅新增算术 nounset 预扫描与 $N 诊断渲染修正;无公开 API、文档或行为删除。
Refs #3251