Skip to content

executor: redirect target field-split verdict for quoted-space words - #3262

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/W-3089
Nov 10, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/W-3089

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3089

问题

重定向目标词把一个含 IFS 空格的引号段与一个替换段拼起来时,rubash 误报 ambiguous redirect,而 GNU bash 按单字段语义建/读拼接出的文件。例:> 'a b'$(printf '')、> "a b"$V(V 空)、>> 'a b c'${V}(V 空)。

根因(GNU 锚点):GNU 的判词在 redir.c:298 redirection_expand——目标词展开后走 subst.c:12397 word_list_split 做 IFS 字段切分,字段数 ≠ 1 才报 ambiguous;引号段产出在 subst.c:4773 quote_string 经 subst.c:11862 add_quoted_string 得到保护,永不被切分。rubash 此前的判词对带标记的展开不做字段切分,而是对剥除载体后的文本做空白扫描,于是引号内的 IFS 空格被误判。

改法(机制级,无形状特判)

  • src/executor/expand_word.rs:expand_redirect_target 对带标记的展开改走与参数管线同一个 IFS 字段切分器(field_split_values_with_ifs),以字段数作判词。信任条件二选一:(a) 标记展开带保护载体(经 markers.rs 的 pair-aware 助手 contains_bare_sentinel 判定,E400 对内成员是数据不是协议);(b) 原始词扫描证明不存在引号内 IFS 字符、也不存在引号内展开点——自定义 IFS 可使引号内空格成为普通数据、永不落载体(如 IFS=: 时空格非 IFS 字符),此时仿真标记本就无可保护,计数字段仍是 GNU 语义。信任且切分恰得一字段时,该字段即文件名——替换结果尾部的 IFS 空格按字段语义处理,不再残留在文件名中(V='x ' 时 GNU 的单字段为 a bx)。
  • src/executor/redirection.rs:>(...) 进程替换的同位点同步采用该判词(两行)。
  • scripts/marker-lint-allowlist.txt:一处裸剥除按仓库既有形态登记为 owner restore chain——依据是 markers.rs restore_bare_sentinels 文档的不变量:带类型的 C0 字节永不以裸 C0 字符到达(恒以 raw-byte 标记对承载),故对 C0 载体的裸剥除不可能折入用户数据。其余两处裸字面消费已改走 pair-aware 助手。

本 PR 删除了什么

无删除。仅新增字段切分判词、两个模块内扫描助手与一条 allowlist 登记;被替代的文本扫描判词保留为无标记词的回落路径(其语义与基底一致,见基底对账)。

验证(Simular box,基底 beab07dc,按逐茎 test result 行与失败名集判读)

腿 基底 头 62e46bb8
本钉 20 格 6 过 / 14 红(失败名集与立案登记逐名全等 = 误报面本身) 20 过 / 0 红
邻茎 1769 / 1673 / 2999 / 1020 — 11/11、3/3、15/15、4/4
lib 双边 1207 过 / 0 红 / 4 ignored 1207 过 / 0 红 / 4 ignored(失败集双边皆 ∅)
-D warnings --all-targets --keep-going rc=101,16 个存量测试面目标 rc=101,错误集与基底逐项全等(同 16 个,零新增;^error 计数 32 = 32)
cargo fmt -- --check — rc=0
marker-lint 基底 rc=0 rc=0(117 registry consts,265 allowlisted sites)
cargo check --tests --target x86_64-unknown-linux-gnu — rc=0

darwin/msvc 跨目标在验证箱上不可判(箱缺跨目标 C 工具链,基底同样失败),留 CI 判读。

门禁与漂移

Refs #3089

Twenty cells for the redirect-target word that joins a quoted segment
containing an IFS space with a substitution segment: GNU creates or
reads the single joined field where the base reports an ambiguous
redirect, plus the ambiguous controls that must keep failing.

Refs #3089
expand_redirect_target now runs the marked (carrier-protected) word
through the same IFS field splitter the argument pipeline uses:
GNU redir.c decides the ambiguous-redirect error from the field
count of the split, not from a textual scan of the expansion.

The count is trusted when the marked expansion carries a protection
carrier, or when a raw-word scan proves no quoted IFS character and
no quoted expansion site exists (a custom IFS can make a quoted
space plain data, in which case no carrier is ever stamped). When
the trusted split yields exactly one field, that field is the file
name, so a trailing IFS blank inside a substitution result is
handled by field semantics instead of surviving into the name.

The marker-lint consumption of the carriers goes through the
pair-aware contains_bare_sentinel helper; the one remaining bare
strip is registered in the allowlist as an owner restore chain
(typed C0 bytes never arrive as bare C0 chars).

Refs #3089
@caomengxuan666
caomengxuan666 merged commit 9c18167 into master Nov 10, 2026
11 checks passed
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