Skip to content

fix(executor): clamp the $() and backtick raw-skip copy loops to the buffer (#875) - #877

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/875-raw-skip-sentinel-clamp
Oct 19, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/875-raw-skip-sentinel-clamp

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #875. 发版阻塞修复,随 niubash v1.4.1 re-release 走(niubash 侧将把 scripts/release/rubash-pin.json 顶到本 PR 的 commit;merge 先于 re-tag)。

变更

  • mark_literal_ifs_chars 的 $(...) 分支(command_prepare.rs:3917 一带)与反引号分支(:3947 一带)的 copy 循环,上界同样 .min(chars.len()) clamp——与 braced 分支 a partially-quoted word is treated as wholly quoted, so field splitting is skipped and the argument count is wrong #743 followup(:3879,probe 2026-10-18,同一 panic 类)完全同款。未闭合体按原样逐字拷贝。
  • 回归测试 ×3:
    • 词 $("a\(未闭合 $( + 引号尾随反斜杠)不再 panic(补丁前红:command_prepare.rs:3919:46, the len is 5 but the index is 5,与 release journey 崩溃同形;run 39233051251 的真实案例 len=132);
    • 词 `a\(未闭合反引号 + 尾随反斜杠)不再 panic(补丁前红 :3949:34);
    • clamp 后普通词/已闭合 substitution 词 byte-identical。

验证

  • 本地 rubash 全套 lib 测试:707 passed / 0 failed(clamp 后)。
  • 红绿对照:同一测试注入 45f537e(pin rev、未打补丁)两条 panic 复现,注入本分支绿。

关联

  • niubash release run 39233051251 的 journey 红(P4-S4/P7-S1/S3/S4 全部是本 panic 杀会话)。
  • niubash 侧配套:rubash-pin.json → cd456ca(PR 随后开到 niubash master)。

…buffer (#875)

mark_literal_ifs_chars copies $(...) and backtick bodies with the
skip_raw_* helpers' return value as an exclusive bound. Those helpers
return beyond-the-buffer sentinels when an unclosed span ends in a
trailing backslash (skip_raw_quote/skip_raw_backtick do index += 2 on
the escape hop): the word $("a\ makes skip_raw_command_substitution
return len+1, and the unclamped copy loop indexes chars[len] and panics
the whole shell — thread 'niu-main' panicked at
executor/command_prepare.rs:3919:46 'index out of bounds: the len is N
but the index is N' (release-journey P7 panic, niubash release run
39233051251; every session boot after a wizard theme pick died).

The braced-parameter branch got exactly this clamp in the #743 followup
(probe 2026-10-18, same panic class); the $() and backtick branches
were missed. Clamp both the same way: an unclosed body is copied
verbatim, which is exactly what the word contains at this stage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant