Repository navigation
Read-time validation of command substitution bodies (P4B) - #3282
Merged
Merged
Conversation
GNU validates a $(...) body when the enclosing command is read (parse.y:4451 parse_comsub), so a body grammar failure kills the input unit before anything in it executes. Rubash only screened bodies on the execution path, so a skipped body never reported and an executed one missed the -c 127 remap. - script_driver: the grouped reader screens each freshly parsed non-interactive unit before execution (diagnostic-owned prefix runs keep their single report; interactive readers unchanged). - executor: screen_comsub_bodies_at_read walks process-substitution bodies, word-shaped texts (re-extracted live-context: single-quoted and backslash-escaped openers are literal and never screened), and nested command bodies; backquote subtrees are skipped (GNU parses those in the child) and here-document bodies are data. A hit is reported once through the existing body-error report, with the parked marker's body-relative lines translated into the reader unit's frame, and aborts with the driver's own status. - parser: an unclosed case inside a substitution body is reclassified per parse.y:4519-4521 — a `)` that cannot close any pattern (armed region with no pattern content yet, or glued to `in` or to the case subject) closes the substitution, so the truncated body reaches the body parser's grammar verdict instead of being classified as an unclosed EOF. Successor-lane repairs on top of the original implementation: the screen walker now owns its extracted marker (the first head build failed E0515), the word scan is quote/escape aware, and parked marker lines are frame-translated (a skipped bad body on a later unit line reported line 1; the execution screen reports the unit line). Refs #2789
… command_substitution.rs; fix command_word_texts heredoc comment (Refs #2789)
caomengxuan666
marked this pull request as ready for review
November 11, 2026 00:02
caomengxuan666
added a commit
that referenced
this pull request
Nov 11, 2026
… read-time validation change) (#3303) Refs #2789 ## 前置条件(合入轮须知) 本 PR 栈内携带 PR #3282 的两个提交(patch-id 与 #3282 头逐一相同)。**本 PR 须在 PR #3282 合入后重栈再合**:重栈时两携带提交自动丢弃,余四提交(提取器测试先行、门两实现、parser 闩、钉两格)。下文计数为队长复核在全栈头 `484eda3d` 上的实测;重栈终头的计数以合入轮复跑为准,形态与判词不变。 ## 本 PR 做了什么 按 review-3282 卷宗 §13 裁定(六修正 + §13.3 确切范围)为 lexer 完整性门补上 case 模式面的三谓词扣留: - `src/lexer/continuation.rs`:门的 staged 与 oracle 两实现同步加入 CloseCharResidualState 四件检查点簿记(`case_pattern_content` / `case_pattern_paren_depth` / `case_pattern_opener_available` / `case_pattern_region_seen`),循环头取更新前快照带到 pop 臂,扣留条件按三谓词(区域内非内容关 / `in` 词在 stage 2 / stage 2 且区域未武装但词非空)判定 `case_body_close`;`UnclosedDelim`、staged case-depth 函数本体、funsub/pattern_paren/arith 臂与 heredoc 跳读未动。 - `src/parser/command_substitution.rs`(闩提交):修正④的完成闩 `case_in_completed_empty`——`in` 在 stage 2 补全后置位、区域簿记后应用、被模式内容与区域解除清除,作提取器关臂第四条件。 - 测试:提取器重分类单测 8 格(三谓词触发 + 四对照 + 闩格)先行提交、红先行证据在案(7 过 1 红,红形态与 §13 预估逐字相符);门等价测试 22 格(staged⇄oracle 逐行前缀、双模式、park/恢复);钉新增两格(空格变体 `-c` 形、空格后随 `-c` 形)。 ## 验收(队长复核实测,全栈头) - 钉 issue2789:全栈 **11/11**;仅 #3282 两提交的中栈为 **9/9**——本 PR 对钉红格的边际为零,增量在端到端两形:外层污染形 `case a in a) echo $(case x in);; esac` 由 2 → **127**、空格后随形 `echo $(case x in ) $(echo ok)` 由静默 0 → **127**(GNU 均为 127,三方亲测)。 - 门等价 22/22;lexer `case_` 过滤 34/34;spotcheck 对 GNU 39/39;eval 拼接见证与双引号形均 127。 - lib 双边名集差 ∅(头较基底 +10 测试:提取器 8 + 等价 1 + 门 1);`-D warnings`(lib+bins,touch + `-v` 证真载)rc=0;`cargo check --tests` rc=0;fmt、marker-lint、UTF-8 全树卫生 rc=0;全栈 diff 零 `libc::`。 - 邻茎 issue381 三格红为基底既存 harness 归一化伪影(三树逐字同形),非本 PR 引入。 ## 残余(已在复核卷宗 §7 给立案建议,归队长裁) `a|`/`a;;` 端到端仍 2(提取器 region 未武装面)、`()` 两形门级不放行(stage 4 解除)、REPL 复合面仍判未闭合、skip 路第三实现无谓词等价物(记账接受建议)。均不阻断本 PR。 ## 本 PR 删除了什么 无删除型改动:全栈净 +1018/−2,删除的 2 行为门两实现 pop 臂的旧条件行(被三谓词条件取代)。重栈后为余四提交的对应形态。
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 #2789
What this changes
GNU validates a substitution body when the enclosing command is read (parse.y:4451 parse_comsub hands the body to the grammar;
)is the substitution's shell_eof_token, parse.y:4519-4521). Rubash screened bodies only on execution paths, so a body the program skips never reported, and an executed body in a -c string missed the 127 remap (shell.c:1471-1472).src/script_driver.rs(+16): the grouped reader screens each freshly parsed non-interactive unit before execution and before unit voiding; interactive readers and diagnostic-owned prefix runs are unchanged.src/executor/command_substitution.rs(+373):screen_comsub_bodies_at_readplus a recursive walker over process-substitution bodies, word-shaped texts and nested command bodies. Word texts are re-extracted with a live-context scan (single-quoted and backslash-escaped openers are literal and yield no node). Backquote subtrees are skipped (GNU parses those in the substituted child); here-document bodies are data and never walked. On a hit the error is reported once through the existing body-error report — with the parked marker's body-relative lines translated into the reader unit's frame — and the unit aborts with the driver's own status (-c 127, file 2).src/parser/command_substitution.rs(+182): live-context word scan, and the in-field unclosed-case reclassification: a)that cannot close any pattern (armed pattern region with no content yet, or glued toinor to the case subject) ends the substitution, so the truncated body gets the body parser's grammar verdict instead of an unclosed-EOF classification.src/parser/mod.rs(+7): executor-facing wrapper for the live scan.What this PR deletes
No tracked file is deleted and no product line is removed: the change is +578/-0 across the four files above. The lane-local probe file used during development was untracked and was removed before the commit; it was never part of the tree.
Verification (slot runs; per-stem verdicts from on-disk logs)
beab07dc: 3 passed / 6 failed (fail-first; the 6 red cells are the defect shapes, the 3 green ones are the controls).issue2789_comsub_read_time_validation): 6 passed / 3 failed. The 3 red cells are listed under "Blocked" below — all three trace to one gate outside this change's file surface, not to the screen.cargo fmt --check(whole tree): clean.RUSTFLAGS="-D warnings" cargo check --lib --bins --test issue2789_comsub_read_time_validationis clean. The full--all-targetscheck stops at pre-existing base test-target defects (three separate runs surfaced three different first failures — an unused import in the failglob stem, a never-used helper in the extdebug stem, a never-read field in the E000 stem; all three files are byte-identical between base and this head), so it never reaches this change's targets.Blocked: three pin cells wait on the completeness gate
echo $(case x in)(and the pattern-start variant with a space afterin) never reach the parser in a -c string, a file, or a sourced file: the input-completeness scan classifies the unit as unclosed (the)is withheld as a case token while a case is open inside the substitution), so the unit dies with the EOF diagnostic at status 2 where GNU reports the body grammar error (127 for -c). The parser-side reclassification in this PR handles the shape whenever it is reached — througheval, the same string already produces GNU's 127 with the matching diagnostic — so the remaining step is the same reclassification in the completeness scanner that owns that gate (src/lexer/continuation.rs), which is outside this lane's file surface. The full analysis and a proposed scanner change are in the lane report. The affected pin cells are the two unterminated-case cells and the sourced-file cell (its sourced script carries the same shape); the spot-check mismatches are the -c forms of the same two shapes.