Skip to content

[cosmetic] for (( i="1;2" )) 算术错误回显泄漏原始控制字符 0x1c:i=\x1c1;2(GNU 逐字回显 i="1;2)(P3) #548

Closed

Description

@caomengxuan666

来源:huck 443 条 divergence issue 全量审计(issues-audit)we-diverge 增量,B 组 B26 + D 组第 2 项(合并开单);huck 侧 issue #602 互证。
审计基准:GNU bash 5.3.0(WSL stdin 法 oracle)× rubash origin/master 764b9dd debug 构建。

最小复现

for (( i="1;2" ; i<3 ; i++ )); do :; done
GNU bash 5.3.0 rubash 764b9dd
错误回显 i="1;2(逐字回显原 token) i=\x1c1;2(双引号字符被渲染成原始 0x1c 控制字符)

语义本身对(引号 ; 不切节、到算术求值才报错,rc 链一致);坏的只是错误回显渲染。另 token 回显尾随空格有微差。

依据

跨实现互证(huck)

优先级建议

P3(消息格式:字节可见但仅错误路径)。

Activity

  1. added
    bug
    gnu-baseline
    P3-low
    on Oct 12, 2026
  2. caomengxuan666 commented on Oct 13, 2026

    @caomengxuan666
    MemberAuthor

    修复 PR:#584(已合入目标 base master,CI 全绿)

    根因

    不只是回显渲染问题——标记字节一路进入了求值输入。src/parser/arithmetic_for.rs 把三个 section 的求值文本建为 token.value 归一化 join,而带引号的 word 在 token value 里以载体协议传输("1;2" 的值是 \x1c1;2,0x1c = 引号胶水位标记,registry 见 src/executor/markers.rs)。该字节既毒化算术求值器,也经 ArithEvalError::render 泄入 evalerror 回显。

    语义契约(vendored bash):make_cmd.c:254-261(section 原文逐字,段首空白跳过、引号保留)+ execute_cmd.c:3171(求值前引号剥离)。修法:section 求值输入改用逐字 capture(段首 trim、注册表码点在诊断边界剥离),求值器原地引号删除后自然复现 GNU 组合。

    字节级前后对比(WSL GNU bash 5.3.0 stdin oracle,od -c)

    修复前(origin/master 7f18b44):

    <argv0>: line 1: ((: i=\x1c1;2: arithmetic syntax error: operand expected (error token is "\x1c1;2")
    

    (od -c 实测两处 034,即 0x1c)

    GNU bash 5.3.0 / 修复后(逐字节一致,含 i=1;2 尾随空格与 token ";2 ",原 issue 记录的"尾随空格微差"也随之消除):

    bash: line 1: ((: i=1;2 : arithmetic syntax error: invalid arithmetic operator (error token is ";2 ")
    

    附带修复(同根因,超出 cosmetic 的实际语义病)

    for (( i="3" ; i>0 ; i-- )); do echo hi; done:修复前整个循环被 i=\x1c3: operand expected 中止(0 输出);修复后与 GNU 一致输出 hi x3。

    验证

    • 逐字节 md5 对比 GNU:issue 复现、for (( i="a;b" ; 0 ; 1 ))(引号 ; 不切节、到求值才报错,与 GNU 同形)、for (( 7++ ; ... ))、裸 for (( i="1;2" )) 解析错形态均 identical。
    • 新增 tests/issue548_arith_for_carrier_echo_regressions.rs(0x1c/C0 载体字节不出现 + GNU 逐字 body 断言 + 成功路径)4 绿;全量 RUST_TEST_THREADS=1 cargo test --no-fail-fast 失败集与 origin/master 基线双向 comm:fix-only 为空(base-only 仅既有本地环境失败 upstream_suite_slice_snapshots);RUSTFLAGS="-D warnings" cargo check、cargo fmt --check 干净;PR CI 全绿。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3-lowbuggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions