Skip to content

test: add fail-first regression pins for hash/type accepting non-executable PATH files (Refs #3825) - #3830

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/3825-hash-type-nonexec-path
Nov 17, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/3825-hash-type-nonexec-path

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

摘要

hash mycmd 与 type -a mycmd 不应接受经 PATH 找到的非可执行文件;GNU 报 not found(rc 1)。当前 rubash 两处皆接受。

修法已落盘:86599fef(共享原语修法,自 #3824 分支 cherry-pick)+ 40f83bd4(两处后验)。回归钉 42b5c09a(9 cells)+ 格式修复 50e1aef5。

根因

PATH 查找本身是 FS_EXEC_PREFERRED(find_in_path_walk_unix,src/executor/path.rs:1283+):无可执行文件时返回首个已存在文件作 file_to_lose_on 回退。该回退对执行面正确(随后 exec 报 EACCES rc 126),对 command -v 与普通 type 的宽容面也正确(GNU 同样宽容),但 hash 与 type -a 两个消费点缺少 GNU 的严格后验:

  • hash(裸名循环,src/builtins/hash.rs:355+):GNU hash.def:214-230 add_hashed_command 对 find_user_command 结果做 executable_file 后验,不过则 sh_notfound。
  • type -a(command_paths,src/executor/lookup_paths.rs:284+):GNU type.def:381 用 user_command_matches(command, FS_EXEC_ONLY, ...) 枚举,只列可执行文件;此前实现以 anchored.is_file() 为准,只验存在。

GNU 锚点

  • hash.def:214-230、findcmd.c:214-223、type.def:381(见上)。
  • type.def:379:普通 type 用 find_user_command(FS_EXEC_PREFERRED),故保持宽容——本 PR 不动 find_user_command 本身。

修法

与 #3824 共享同一原语修法:unix is_executable_file 排除目录(共享修法提交 53acd684,见 #3824 的 PR #3829,本分支 cherry-pick 为 86599fef)。在此之上(40f83bd4):

  1. hash 裸名循环:find_user_command 返回后做目录排除的可执行性后验,不过则删条目、报 hash: <name>: not found、rc 1。
  2. command_paths(-a 枚举,唯一调用方是 describe_name_all_with_io):unix 侧只推可执行候选。

本 PR 删除了什么

无删除(新增回归钉 tests/issue3825_hash_type_nonexec_path.rs,9 个 cells,含 command -v / 普通 type 宽容面守卫)。

验证(车道腿,UNVERIFIED-BY-CAPTAIN)

  • Linux fail-first(新服务器,base 969230b + 钉):stem 3825 rc=101,5 pass / 4 fail——恰为 4 个缺陷 cells(hash-644、hash-000、hash-nostore、type-a),5 个对照(含 command -v 与普通 type 宽容面)全过。
  • Linux 修绿:CI census(run 43998653492,job 133756914878,Linux 全 stem)9/9 PASS。服务器修绿腿因新服务器严重过载(load ~30、swap 满,rustc 70 分钟仅 70 秒 CPU)无法在合理时间内完成,车道已停掉该腿;Linux 修绿证据以 CI census 为准。
  • CI(head 50e1aef):除 goldens + census 外全绿(CLI、cross-target darwin/linux、Rust tests、macOS、Shell functionality、Windows compile、ledger)。goldens = 恰 2 个基线 cells(issue_753::case_9、upstream_suite_slice_snapshots)。census 87 cells,与 test: add fail-first regression pins for empty hash -p path (Refs #3824) #3829 的 80 cells 之差仅为已知的 assoc/at/$@ 不稳定族 + 2 个 churn cells;唯一 hash/type 相邻红 cell(type_a_empty_path_element_visit_counts,[bug] type -a reports the cwd match once per empty PATH element; GNU collapses adjacent empty elements #2943)在 test: add fail-first regression pins for empty hash -p path (Refs #3824) #3829(其 diff 不含 command_paths 改动)上同样红,属基线/抖动,非本修法回归。
  • X299:fmt 0(5 文件)、-D warnings check 0、lib 双边 1368/1/4 两侧完全一致(唯一红 cell 为已知 Windows 基线 issue2084)、hygiene 三项全 0;钉 stems 为 unix-gated,Windows 上 0 tests。
  • GNU oracle:种子 R133-B 在 GNU bash 5.3.20 上 11/11(含普通 type 宽容面对照);钉 cells 即种子断言的测试化。

…utable PATH files (Refs #3825)

GNU anchors: hash.def:214-230 add_hashed_command (executable_file
post-check on the find_user_command result) + type.def:381
describe_command (type -a enumerates via user_command_matches with
FS_EXEC_ONLY). command -v and plain type stay lenient (controls).

UNVERIFIED-BY-CAPTAIN
…efs #3824)

GNU findcmd.c:214-223 executable_file requires FS_EXECABLE and not a
directory; the unix is_executable_file was a bare access(X_OK), which
admits directories (search permission). That made phash_search_spelling
return "./" for a stored empty hash -p path: hash -t printed "./"
and running the entry failed "./: Is a directory" (rc 126) instead
of GNU's ": No such file or directory" (rc 127).

Shared fix commit for #3825 (same commit cherry-picked onto the
#3825 branch): the #3825 hash/type post-checks call this predicate.

UNVERIFIED-BY-CAPTAIN
…efs #3825)

GNU hash.def:214-230 add_hashed_command applies an executable_file
post-check on the find_user_command result; GNU type.def:381
describe_command enumerates type -a via user_command_matches with
FS_EXEC_ONLY. The PATH walk stays FS_EXEC_PREFERRED (correct for
execution — the exec then fails EACCES — and for the lenient faces),
so the strict gate lives at the two consumption points:

- hash bare-name loop: a non-executable hit is not stored; the
  builtin reports "hash: <name>: not found", rc 1.
- command_paths (-a enumeration, sole caller describe_name_all_with_io):
  unix side pushes only executable candidates.

command -v and plain type stay lenient (controls in the pins).
Depends on the shared is_executable_file fix (53acd68, cherry-picked
from the #3824 branch).

UNVERIFIED-BY-CAPTAIN
Formatting only (server rustfmt --edition 2021); no semantic change.
@caomengxuan666

Copy link
Copy Markdown
Member Author

PR #3830 第1轮 — 建议:PASS
head: 50e1aef base(merge-base): 969230b 文件: 4 个 +203/-2
关联 issue: #3825(状态:open,我核过的时间:2026-11-17 12:26 +0800)

机制核查:

  • GNU 锚点属实:findcmd.c:214-223 executable_file = (s & FS_EXECABLE) && ((s & FS_DIRECTORY) == 0);hash.def:213-230 add_hashed_command 先 phash_remove 再 find_user_command,结果过 executable_file 后验,不过则 sh_notfound+rv++→opt=EXECUTION_FAILURE(hash.def:206);type.def:381 describe_command 的 -a 枚举用 user_command_matches(command, FS_EXEC_ONLY, ...)(findcmd.c:532/580-586 只收 FS_EXECABLE),而普通 type(type.def:379)与 command -v 走 find_user_command(FS_EXEC_PREFERRED,findcmd.c:591-600 的 file_to_lose_on 回退保留非可执行已存在文件)——「严格消费点后验、宽容面不动」的切分与 GNU 一致。
  • 修法三处均落在正确消费点:is_executable_file unix 臂加 !path.is_dir()(与 GNU executable_file 的目录排除对齐,is_dir 随 stat 穿透符号链接);hash 裸名循环在 find_user_command 返回后做后验,失败则 table.remove+hash: <name>: not found+EXECUTION_FAILURE+continue(与 GNU phash_remove 前置删除 + sh_notfound + 逐词继续等价);command_paths 的 -a 枚举把 anchored.is_file() 收紧为 is_file() && is_executable_file()。
  • diff 无顺手改动、无桥接/翻译层。相邻说明:is_executable_file 在本 PR 树上的其他调用点(src/bin/bash.rs:199/209/218/258 自身解析、external_inner.rs:4949/6509 ENOEXEC 回退门、completion_executable_qualifies path.rs:3983)同步获得目录排除——全部收敛向 GNU executable_file 语义(目录 execve 必 EACCES→126),无回归面;PR 正文「唯一调用点 hash.rs:501」的表述不确(实为 test: add fail-first regression pins for empty hash -p path (Refs #3824) #3829 语境下的说法),但不影响正确性。

腿(逐项给数字与名字):

  • 钉自跑:issue3825_hash_type_nonexec_path 9 passed / 0 failed(WSL Linux cargo +1.99.0,head 50e1aef;钉为 cfg(unix),Windows 侧 0 tests)
  • fail-first:base 969230b + 原样钉文件 → 5 passed / 4 failed;红名 = {issue3825_hash_nonexecutable_path_file_is_not_found, issue3825_hash_mode_000_path_file_is_not_found, issue3825_hash_nonexecutable_path_file_is_not_stored, issue3825_type_a_nonexecutable_path_file_is_not_found},绿名 = {command_v/type 宽容面、exec 存储、跳过非执行到后续可执行、rehash 恢复}——与 PR 声称「4 缺陷格 + 5 对照」完全一致
  • lib 双边(WSL cargo +1.99.0):head 失败名集 {}(1267 passed / 0 failed / 4 ignored)/ base 失败名集 {}(1267 passed / 0 failed / 4 ignored)/ 差集 ∅
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --locked --lib --bins --tests → Finished,0 警告
  • 卫生:rustfmt --check(hash.rs / lookup_paths.rs / path.rs / 钉文件)rc=0;marker-lint OK(118 consts / 268 allowlisted);utf8-boundary clean
  • CI(head 50e1aef run 43998653492):红任务 2 个——「GNU regression goldens and canaries」红格 = {issue_753::case_9_declare_indexed_operand_binds_nothing, upstream_suite_slice_snapshots} = 基线;「Regression pin stem census」87 failed tests 均为基线红族(issue1253/1034/2308/2613/3185/3211/977 等长红 stem),新钉 issue3825_hash_type_nonexec_path 在 census 9/9 全过。相邻红 cell issue2943_type_a_empty_path_element_visit_counts([bug] type -a reports the cwd match once per empty PATH element; GNU collapses adjacent empty elements #2943,type -a 面)我在 base 与 head 本地同测均 FAILED 同断言(PATH="::" left 1 right 2)→ 基线/既有红,非本 PR 引入。其余任务全绿(CLI、cross-target darwin/linux、Rust tests、macOS、Shell functionality、Windows compile、ledger、niubash build)。
  • GNU 对照:WSL /usr/local/bin/bash = GNU bash 5.3.20(1)-release (x86_64-pc-linux-gnu);探针脚本 D:/repo/rubash-devin-y1/target/probes/case3825.sh(wslrun.sh 去 CRLF 后经 /usr/bin/bash 间接调用,避免 wsl.exe 引号吞参):hash mycmd3825(644)→ hash: mycmd3825: not found rc=1 且不入表;hash -t rc=1;type -a → type: mycmd3825: not found rc=1;type/command -v → ./mycmd3825 rc=0(宽容面);hash ex3825(+x)→ rc=0、hash -t → ./ex3825;非执行在前可执行在后 → hash -t → ./b3825/skipme。rubash head 逐格一致。
  • 环境注记:本机 WSL /usr/bin/mycmd、/bin/mycmd 存在 2 字节探针残留("x",+x),会污染 PATH=/usr/bin:/bin 形状的对照;已删除,复测干净。

F 点:无

续作记录:无(只审未改)

未跑/VOID 的腿:无

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 17, 2026 04:32
@caomengxuan666
caomengxuan666 merged commit b89450c into master Nov 17, 2026
10 of 12 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