Repository navigation
fix(parser): arithmetic-for sections evaluate the verbatim (( )) capture, carrier bytes never reach evalerror echoes (#548) - #584
Merged
Conversation
…ure, carrier bytes never reach evalerror echoes (#548) GNU contract: make_cmd.c:254-261 splits the ARITH_FOR_EXPRS text into three sections by scanning with skip_to_delim, keeping each section's text verbatim (leading whitespace skipped, quotes intact); execute_cmd.c:3171 eval_arith_for_expr strips quotes before evalexp, so evalerror echoes the dequoted section and the evaluator never sees a carrier byte. rubash's parser built each section as a token-value join instead: quoted sections travel through token values as carrier-marked text, and the 0x1c quoted-glue carrier reaching the arithmetic evaluator (a) failed the evaluation - for (( i="3" ; ... )) aborted with 'operand expected' where GNU bash 5.3.0 runs three iterations - and (b) leaked the raw carrier into the evalerror echo (i=\x1c1;2 where GNU echoes 'i=1;2 '). Feed the evaluator the whitespace-carrying capture (leading blanks trimmed, registry codepoints dropped at the diagnostic boundary); the evaluator's in-place quote removal then reproduces the GNU composition byte for byte: for (( i="1;2" ; i<3 ; i++ )); do :; done GNU 5.3.0: bash: line 1: ((: i=1;2 : arithmetic syntax error: invalid arithmetic operator (error token is ";2 ") before: ((: i=\x1c1;2: arithmetic syntax error: operand expected (error token is "\x1c1;2") after: byte-identical to GNU (section trailing blank kept in echo and token) Byte-verified vs WSL GNU bash 5.3.0 (stdin oracle, od -c): the issue repro, for (( i="a;b" ; 0 ; 1 )), for (( 7++ ; ... )), and the bare for (( i="1;2" )) parse-error form are byte-identical after the fix; for (( i="3" ; i>0 ; i-- )) prints hi three times like GNU. Parser expectations for the update section now record the verbatim capture's trailing blank before )) (make_cmd.c keeps everything up to the section-terminating ';'). New tests/issue548_arith_for_carrier_echo_regressions.rs asserts carrier-byte absence and the GNU-verbatim diagnostic bodies.
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.
问题
for (( i="1;2" ; i<3 ; i++ )); do :; done的算术错误回显泄漏内部标记字节 0x1c(issue #548,P3):rubash 报i=\x1c1;2,GNU 逐字回显i=1;2。字节级取证(WSL GNU bash 5.3.0 stdin oracle,
od -c)修复前(origin/master 7f18b44,逐字节):
GNU bash 5.3.0:
修复后与 GNU 逐字节一致(含
i=1;2尙留的尾随空格与 error token";2 "),0x1c 不再出现。根因(file:line)
src/parser/arithmetic_for.rs把三个 section 的求值文本建为 token.value 归一化 join。带引号的 word 在 token value 里以载体标记协议传输:"1;2"的值是1c 1;2(0x1c = 引号胶水位标记,src/executor/markers.rs)。该标记字节一路进入算术求值器输入,既毒化求值也进入 evalerror 回显渲染(ArithEvalError::render,src/executor/arithmetic/parser.rs)。语义契约锚定(vendored bash,仅引用不搬运)
third_party/bash/make_cmd.c:254-261make_arith_for_command:section 文本 = 原文逐字(段首空白跳过、引号保留)。third_party/bash/execute_cmd.c:3171eval_arith_for_expr:求值前先做引号剥离,求值器永远看不到引号字节。raw_parts,段首 trim,注册表码点在诊断边界剥离);求值器内部的原地引号删除(bare(( ))路径已与 GNU 字节一致)随后自然复现 GNU 组合。附带修复(同根因)
for (( i="3" ; i>0 ; i-- )):修复前整个循环因i=\x1c3: operand expected中止;修复后与 GNU 一致输出hix3。验证
cargo check+RUSTFLAGS="-D warnings" cargo check通过;cargo fmt --check干净。tests/issue548_arith_for_carrier_echo_regressions.rs:4 测试绿(0x1c/C0 载体字节不出现 + GNU 逐字 body 断言 + 成功路径 rc/stdout)。for (( i="a;b" ; 0 ; 1 ))、for (( 7++ ; ... ))、裸for (( i="1;2" ))解析错形态均 md5(identical)。RUST_TEST_THREADS=1 cargo test --no-fail-fast:失败集与基线(origin/master 独立工作树)双向 comm — fix-only 为空;base-only 仅upstream_suite_slice_snapshots(既有本地环境失败,与本改动无关,基线工作树单独复现)。i++,make_cmd.c 保留;前全部文本)。Closes #548