Repository navigation
fix(cond): decode raw-byte pairs at the [[ =~ ]] regex boundary (Refs #3545) - #3931
Merged
Merged
Conversation
Fail-first nails for #3545: carrier bytes (0x0c, 0x14..=0x1f) in the regex operand — $'...' literal form and ${c} after '|' — must match as GNU 5.3.20 does (execute_cmd.c:4068/4096). UNVERIFIED-BY-CAPTAIN
…3545) Carrier bytes (0x0c, 0x11, 0x13, 0x14..=0x1f) ride rubash transport as U+E000 raw-byte pairs, but decode_command_substitution_payload only restores the U+E319 comsub sentinel. The quoted regex path (regex_rhs_marked_chars via shell_text_to_raw_bytes) decoded the pattern to raw bytes while the subject stayed pair-encoded, so $'...' literals and ${c} after '|' never matched; the unquoted path only matched by accident of both sides staying encoded. Decode both spellings at the regex boundary — pattern in compile_conditional_regex_uncached, subject at the three match entry points — so pattern and subject meet as the same raw bytes, the normalization the #729 glob side already applies. GNU: execute_cmd.c:4068 cond_expand_word (mode 2) + :4096 sh_regmatch receive the expanded operands as raw bytes; subst.c:4114 QGLOB_REGEXP only literalizes quoted metacharacters. UNVERIFIED-BY-CAPTAIN
caomengxuan666
marked this pull request as ready for review
November 18, 2026 19:43
caomengxuan666
added a commit
that referenced
this pull request
Nov 18, 2026
fix(exec): classify empty command word as not found 127 (Refs #3317) ## 根因 `exec ""` 应报 not found、rc 127,rubash 报 `cannot execute: Is a directory`、rc 126。 根因在 `src/builtins/exec.rs` 的 as-written 目录探针(rubash#2661 引入):探针把操作数 join 到 session cwd 后再 `stat`。`cwd.join("")` 本身就是 cwd(一个目录),于是空词被读作 cwd 目录、误分类为 EX_NOEXEC(126)。 ## GNU 锚点 - `builtins/exec.def:155-168`:搜索失败(command == 0)时,`file_isdir(args[0])` 决定 126 vs `sh_notfound` / EX_NOTFOUND(127)。 - `general.c:812-817`:`file_isdir` 即 `stat(fn) == 0 && S_ISDIR`;`stat("")` 以 ENOENT 失败,所以空词不是目录,是 not found。 - 探针的其余部分不变:`exec .` / `exec somedir` 仍为 126(#2661 钉守护);slash 分支与 PATH 查找不动;普通外部命令分类器本来就对无分隔符的空词返回 None、报 127,不受影响。 ## 修复 空词跳过目录探针(`stat("")` 永远失败);非空词的 #2661 探针原样保留。只改 `src/builtins/exec.rs` 一个文件。 ## 回归钉 `tests/issue3317_exec_empty_command.rs`(8 钉):`exec ""`、`exec ''`、带额外参数、子 shell、函数内、`shopt -s execfail` 形态(`after rc=127`),另加真不存在路径(127)与 `exec .`(126)两个对照。 Fail-first(新服务器 [email protected],GNU bash 5.3.9 作 oracle,commit 6d9f2cb):6 红 2 绿——6 个空词钉全红(报 126),2 个对照钉绿;GNU oracle 同形全为 127 / execfail `after rc=127`。 绿腿(同机,commit db40bb5,`-j 1`,`scrubbed_cargo.py`): - 钉 stem `issue3317_exec_empty_command`:**8/8 绿**。 - 邻茎:`issue2661` 5/5、`issue3316` 7/7、`issue3148` 8/8 与 14/14 全绿;`issue3310` 20/21,唯一红为 `issue3310_plain_spawn_env_keeps_live_level`(plain-spawn 的子进程 SHLVL 得 6、钉期望 5;GNU oracle:`$SHLVL` 读 6、子进程 env 得 5)。 - 该红与本 PR 无关:它走 plain-spawn 路径(`rubash -c /usr/bin/env`,不进 exec 内置),且在 base `db580be6` 的 worktree 上单测复现完全相同(0/1 红)——**基底已红**,请队长另行处置(疑似 #3310 的 SHLVL 导出面残差)。 - 全量 lib:1280 passed / 0 failed / 4 ignored(fix 提交 03f9076);`RUSTFLAGS="-D warnings" cargo check --locked --lib --bins` rc=0(同提交)。db40bb5f 相对 03f9076 仅为空白格式 + 钉期望行号修正,lib 全量未在该提交上重跑(当时构建槽已被 #3917 车道占用,未抢槽)——请队长复核时补跑。 - `rustfmt --check`(两改动文件):rc=0。整仓 hygiene 脚本 `scripts/check-rustfmt.py` 仍报 3/12 批有 diff,但剩余 diff 全在未动文件(`pipeline_exec.rs`、`shell_options.rs`、`issue3546`、`issue3894` 钉)——基底既有格式漂移,非本 PR 引入,不在本 PR 里顺手改。 未完成腿:Windows 面(X299 反向隧道仍断,2026-11-19 02:42 实测 2666 refused)**PENDING**;box(钱包空、休眠)与老服务器(须经 box 跳转)均不可达,本轮 Linux 腿走新服务器。 ## 本 PR 删除了什么 无。未删除任何文件、函数、测试或公开面;只把目录探针的适用域收窄到非空词。`docs/api-ledger.md` 未动;未碰 `src/lexer/continuation.rs`。 UNVERIFIED-BY-CAPTAIN ## 队长复核(头 db40bb5,run 44377890814) - census **79**,唯一新增为 issue2340 抖动族一格;自带钉 **8/8 绿**;issue2883 一格翻绿。 - goldens 仅基线二名(lib 1383/0 通过);CLI 仅 coproc 抖动格;darwin 作业 cancelled/steps=[](未运行,非产品红);其余全绿。 - 服务器腿:fail-first 6 红 2 绿、绿腿 8/8、邻茎 issue2661/3316/3148 全绿、-D warnings rc=0、rustfmt 干净;**全量 lib 在 fixup 头 db40bb5 上补跑确认:1280 passed / 0 failed / 4 ignored(LEG-RC=0)**。 - 邻茎红 `issue3310_plain_spawn_env_keeps_live_level` 已另立 **rubash #3932**(plain-spawn SHLVL 导出残差),不属本 PR。 - 与 #3931 合入点零交集(程序化核验:db580be6...36cc7d9 仅改 conditional.rs + #3545 钉),故不经 update-branch 直接合。
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.
根因
载体字节(0x0c、0x11、0x13、0x14..=0x1f)在 rubash 传输层以 U+E000 raw-byte pair 编码存储,但
[[ =~ ]]两侧的解码并不对称:regex_rhs_marked_chars经shell_text_to_raw_bytes)把 pattern 侧的 pair 解回裸字节;decode_command_substitution_payload,它只还原 U+E319 comsub sentinel,不动 U+E000 pair;$'...'字面形与|后的${c}(走带引号路径)pattern 为裸字节、subject 为 pair 编码,永不匹配;而不带引号的a${c}b形两侧都保持 pair 编码,只是碰巧一致才匹配。修法:在 regex 边界上把两种拼写都解开——pattern 在
compile_conditional_regex_uncached入口、subject 在三个 match 入口(conditional_regex_match/conditional_regex_match_status/conditional_quoted_regex_match_status),共用一个decode_regex_operand(sentinel 先解——它只产 U+0000..=U+00FF,不可能造出 pair introducer——再折叠 raw-byte pair)。这是 #729 glob 侧已在用的同一归一化。GNU 锚点
execute_cmd.c:4068arg2 = cond_expand_word (cond->right->op, mode)(=~且 compat > 31 时 mode 2)、:4096sh_regmatch (arg1, arg2, ...):两侧展开后都以裸字节进 regcomp/regexec;subst.c:4077cond_expand_word、:4114QGLOB_REGEXP(pathexp.c:212quote_string_for_globbing)只把带引号的 regex 元字符字面化,载体字节本身是数据,原样进 regcomp。改动
src/executor/conditional.rs:新增decode_regex_operand,4 处调用(pattern 1 + subject 3)。不碰src/executor/parameter_replace.rs(在飞 PR fix(executor): zero-length advance and literal U+E000 stay on match-unit boundaries (Refs #3921) #3926)、src/executor/embedded_parameters.rs(在飞 PR executor: protect literal ' ' under null-IFS / W_SPLITSPACE (dollar-at-star9) #3925)、src/lexer/continuation.rs、docs/api-ledger.md。tests/issue3545_regex_operand_carrier_bytes.rs:3 个钉(issue 原样复现循环、全载体集 15 字节 × var/alt/lit 三形 + 3 个非载体对照、|位置对照 +BASH_REMATCH[0]字节值)。验证(新服务器 [email protected],Linux;本地 VM 未构建)
alt=n、lit-n;全集 15 字节y n n;x|${c}与${c}|x为 y、仅带引号的$'\\x01'|${c}为 n——正是带引号路径解码不对称的证据)。=~silently overwrites a readonly BASH_REMATCH; GNU errors and keeps the stale value #1365 BASH_REMATCH、[bug] set -u skipped for =~ RHS expansion #1177/[bug] Cosmetic: invalid-regex [[ =~ ]] parse diagnostics differ (GNU names the operator, niu names ']]') #1290/[bug] [[ =~ ]] invalid-regex diagnostic passes regerror() text through (GNU: "invalid regular expression '<pat>': ...") #1491/[bug] [[ =~ ]] accepts [[:word:]] and [[:ascii:]]: GNU rejects unknown POSIX class names with rc=2 #1717/[bug] [[ =~ ]] rejects bracket expressions containing non-ASCII characters in the C locale ("invalid regular expression") #3791/[bug] [[ string =~ ^(a|b)$ ]] with unquoted parenthesized regex aborts the parse: 'unexpected end of file from (' — pbb is_hex_color section dies #322/[parse] =~ regex word with unquoted | + reserved word (case/if) rejected in while/until condition — #322 residue (breaks shellapi odsel) #461 regex、bats file_setup_teardown #5/#6: nested-run failure trace lines land at different indices #2981/bats timeout.bats: per-test timeout watchdog never fires; [[ ]] with '|' in generated -c code errors #2987/[[ == ]] quoted RHS with extglob group never reaches the extglob matcher #3100 quoted RHS、[bug]=~dot matches a full char, GNU matches one byte #1061/1242);RUSTFLAGS="-D warnings" cargo check --locked --lib --binsexit 0;rustfmt 两文件 OK;复现脚本用修后二进制跑出与 GNU 逐字节一致的输出。本 PR 删除了什么
什么也没删除。只改
src/executor/conditional.rs(+36/−8)并新增一个测试文件;没有删除函数、文件、公开面或行为分支。decode_command_substitution_payload的其余 10 处调用不受影响。UNVERIFIED-BY-CAPTAIN