Repository navigation
fix(executor): consume fatal arith evalerror at the [[ ]] command boundary (Refs #3382) - #3444
Merged
Merged
Conversation
…ndary (Refs #3382) A fatal $(( )) inside a [[ ]] operand latched the arithmetic error flags past the [[ ]] command: the NEXT command was discarded by abort_on_expansion_errors instead of running (same family as #3287, but the [[ ]] wrapper never consumed the flags at all). GNU's evalerror jumps DISCARD for the current command only (expr.c evalerror -> eval.c:111 reader_loop), so the [[ ]] command itself owns the failure: take_conditional_arith_evalerror consumes the three flags as one error record at the [[ ]] boundary (with-redirects wrapper and the late-dispatch arm) and returns the DISCARD class, and the list loop consumes evalerror_arith_pending when it absorbs the DISCARD so the errexit exemption ends with the discarded line. UNVERIFIED-BY-CAPTAIN
This was referenced Nov 12, 2026
caomengxuan666
added a commit
that referenced
this pull request
Nov 14, 2026
…efs #2764) Refs #2764. ## 根因 case 模式词里的未加引号 <(...) / >(...) 被原样收作模式文本,模式展开路径从不执行它:体不跑、也不拼出 /dev/fd/N 模式。同一位置的命令替换 $(...) 早已执行。 ## 修法 - `expand_case_pattern`(src/executor/compound_exec.rs):在任一展开分支跑之前,复用词管线的替换执行载体 `materialize_for_list_process_substitutions` 把 fd 路径拼进模式文本与 raw 文本。派生用 `WordMetadata::new` 对 raw 文本的 quote-aware 扫描,加引号的 span 从不在派生表里,故保持字面量;每 attempt 重新 materialize,与 GNU 的 per-attempt 重展开一致。 - 分支判定与下游消费一致:`quoted` 只算一次;有 procsub 时用 `case_pattern_raw_has_outside_quotes` 排除体内部引号(体内的引号属于子进程,随 splice 消失),下游复用同一判定,不再二次判定。 - case 命令 wrapper:无重定向面与有重定向面都在 case 完成时 finish 其 >(...) 体,使作为最后一条命令的 case 也不丢 output 体。 ## GNU 锚点(bash 5.3.20) - execute_cmd.c:3712:case 循环每 pattern 调 `expand_word_leave_quoted(list->word, 0)`;3733-3736:模式不做 quote removal。 - subst.c:11365-11385:`expand_word_internal` 的 `<`/`>` 臂;引号内(`Q_DOUBLE_QUOTES`)走 `add_character`,保持字面量。 - subst.c:1311 `extract_process_subst`:原样抽体;subst.c:6362 `process_substitute`:fork 子进程、拼 `/dev/fd/N`。 - 探针:车道 probes/gnu{1,2,3,5}.sh 在 GNU 5.3.20 实测,钉期望即其实测结果。 ## 回归钉 tests/issue2764_case_pattern_procsub.rs(20 tests):fd 路径匹配、变量词、<(...) 体副作用、>(...) 体副作用(case 后立即检查)、引号字面量、glob 后缀(未加引号 `*` 匹配、加引号 `'*'` 字面不匹配)、词中/前缀拼接、双 procsub 不同 fd、体输出不是模式、comsub 对照、逐 arm 重展开、extglob 候选、count-in/out/two-arms 计数(每 attempt 一遍)、Q5/Q5b/Q5m/Q5o 体内置引号匹配。 ## 已验证(队长复核,卷宗 ~/workspace/review-3459/CAPTAIN-VERIFY.md §14) - 钉头 20/20;基底 fail-first 4 passed / 16 failed(16 红全为 procsub 缺陷面)。 - GNU oracle Q5 四形逐字 GNU==HEAD;嵌套 procsub 形亦 MATCH。 - lib 双边失败名集为空(1246 passed / 0 failed / 4 ignored,双边一致);`RUSTFLAGS="-D warnings"` rc=0;fmt/UTF-8 卫生全绿。 - 合并形态重验(update-branch 后合并头 f653f36):钉 20/20;邻居 issue3276 19/19、issue3416 5/5、issue3333 18/18、case_command_head_bash_command_regressions 4/4;终头 CI(run 43610297783)三红唯一格为 issue2875(已知基线,本地 lib 双边皆过)。 - `[[ ]]` procsub 面不在本 PR 范围(卷宗 §8;待 #3444 合入后队长另立),不立案、不扩面。 ## 本 PR 删除了什么 无删除:只改 `expand_case_pattern` 内的展开输入与 case wrapper 的 finish 调用;无公开面变动,无文件删除。
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿(逐项给数字与名字):
F 点:无 续作记录:无 未跑/VOID 的腿与相邻残差:
|
caomengxuan666
marked this pull request as ready for review
November 15, 2026 02:06
This was referenced Nov 15, 2026
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 #3382
现象
GNU:除零诊断后
echo after正常执行。rubash:致命标志在[[ ]]操作数求值后泄漏到下一命令,echo after被 discard(与 #3287 同机制——触发命令边界未整条消费evalerror_arith_pending;但[[ ]]分派缺自己的 abort 检查,标志甚至能越过下一个[[ ]])。根因(GNU 源码先行)
GNU
expr.c的evalerror打印诊断后sh_longjmp(evalbuf, 1);evalexp(expr.c:429-445)的 setjmp 捕获返回 0,失败的算术展开产出&expand_wdesc_error,调用方跳 DISCARD——eval.c:111reader_loop 只丢弃当前逻辑行的剩余部分;execute_cmd.c:4132execute_cond_command执行测试,GNU 不存在跨命令的错误状态。rubash 把算术错误记在三面旗(arithmetic_expansion_error/arithmetic_fatal_error/arithmetic_nonfatal_error)+evalerror_arith_pending里,而[[ ]]的两条分派路径(command_prepare.rs 的 with-redirects 包装与 command_dispatch_late.rs 的 Conditional 臂)从不消费它们,于是下一命令的abort_on_expansion_errors把无辜命令丢弃。修复
src/executor/conditional.rs:新增共享 helpertake_conditional_arith_evalerror——三面旗作为一条错误记录整体消费(nounset 除外,它走自己的 FORCE_EOF 路径),并把evalerror_arith_pending置位以武装 DISCARD 类([bug][regression] set -e: arithmetic expansion error exits the whole shell instead of discarding the current command (#1253) #1518:errexit 提升跳过该类,set -e下 DISCARD 本身不退出)。src/executor/command_prepare.rs:with-redirects 包装在 [bug] Slice error inside [[ ]] does not abandon rest of line (GNU skips it; sibling of #1240) #1422 检查之前消费并返回ExpansionFailure(1)(DISCARD 类);arith 优先于 conditional_error——arith 致命意味着后续操作数仍跑过,conditional_error 可能后设,而 DISCARD 必须武装 errexit 豁免。src/executor/command_dispatch_late.rs:Conditional 臂同样消费(nounset 检查先行,FORCE_EOF 永不降级为 DISCARD)。src/executor/ast_exec.rs:列表循环的 DISCARD 臂吸收跳跃后消费evalerror_arith_pending,豁免随丢弃行终结——set -e下后续false仍退出(否则豁免泄漏,错误地豁免后续失败)。回归钉
tests/issue3382_bracket_operand_fatal_leak.rs(17 格,GNU bash 5.3.20 oracle 逐字节对账):canary、状态 1、同行丢弃/次行执行、&&/||链、if条件、set -e不退出 + 后续失败仍退出、set -unounset 仍致命、右操作数、取反、连续两条、[[ ]]/(( ))/let/赋值后续均干净、#3287 赋值对照。本 PR 删除了什么
无删除。本 PR 为纯新增(+423/−0):一个 helper、两处边界消费、一个 DISCARD 吸收点、一个钉文件;无函数、无文件、无公开 API 被删除或改名。
UNVERIFIED-BY-CAPTAIN