Skip to content

Fix #3551: carry HASH_CHKDOT in hash table entries - #3604

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3551-hash-chkdot
Nov 17, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3551-hash-chkdot

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

GNU carries a per-entry HASH_CHKDOT flag (hashcmd.h:34) seeded from the global dot_found_in_search (findcmd.c:78): every find_user_command_in_path resets it at walk entry (:632) and sets it when a .-leading PATH element resolves to the session cwd (same_file, :550-551) — evaluated per element before the element's hit test. phash_insert stores it: from walk resolutions (findcmd.c:416-426) and hash NAME rehashes (hash.def:225), while hash -p (hash.def:195) and BASH_CMDS[] writes (variables.c:1739) pass a literal 0.

phash_search (hashcmd.c:146-191) applies the CHKDOT/RELPATH arm on every serve: ./NAME (or ./<stored relpath>) wins while that dotted form is executable; a stored .-leading path resolving to . unexecutably counts as not found and falls through to a PATH walk whose phash_insert replaces the dead entry.

Rubash stored only the resolved path, so PATH=.:$PATH; hash foo never served a later-created ./foo, and dead hash -p entries shadowed the PATH walk permanently.

Changes

  • Per-session dot_found_in_search side channel in CommandLookupStores, reset and re-stashed by every PATH walk (GNU-faithful, including per-element ordering).
  • chkdot as a 4th field in __RUBASH_HASH_TABLE entries; all five insert sites pass the flag GNU passes (0 for hash -p / BASH_CMDS / standard-path inserts, the walk verdict otherwise).
  • Shared phash_search_serve arm used by hashed_path (exec/type) and hash -t; the exec mirror consult returns the served spelling verbatim, so post-cd ENOENT diagnostics keep the ./elem/name form (rubash#2696).
  • hash NAME records the as-written join via find_user_command_as_written (GNU stores the recorded spelling, not the anchored candidate).
  • record_command_resolution distinguishes phash hit (bump times_found, keep spelling) from walk insert (replace entry) — hashlib.c:254 vs findcmd.c:416.

Verification

  • 8 script-file probes byte-identical to vendored GNU bash 5.3.20: CHKDOT serve, dot-element ordering (before vs after hit), hash -p zero flag, RELPATH miss fallback, hits accounting.
  • 4 new pins in tests/issue3551_hash_chkdot.rs.
  • Neighboring pins green: issue1361/1360/1362/1368/1382/1489/1551/1648/2518/2696/2736/3020/3076/1047/1265/1459 (79 tests).

Fixes #3551

GNU keeps a global dot_found_in_search (findcmd.c:78) that every
find_user_command_in_path resets at walk entry (findcmd.c:632) and sets
when a '.'-leading PATH element resolves to the session cwd
(same_file at findcmd.c:550-551), evaluated per element before its hit
test. phash_insert stores it as the entry's HASH_CHKDOT flag
(hashcmd.h:34): from the walk at findcmd.c:416-426, from `hash NAME`
rehashes at hash.def:225 — but `hash -p` (hash.def:195) and
BASH_CMDS[] writes (variables.c:1739) pass a literal 0.

phash_search (hashcmd.c:146-191) applies the CHKDOT/RELPATH arm on every
serve: `./NAME` (or `./<stored relpath>`) wins while executable; a
stored '.'-leading path resolving to '.' unexecutably is a miss that
falls through to a PATH walk, whose insert replaces the dead entry.

Rubash stored only the resolved path and ignored the flag entirely, so
`PATH=.:$PATH; hash foo` never served a later-created `./foo`, and dead
`hash -p` entries shadowed the PATH walk forever.

- Track dot_found per walk in a per-session side channel in
  CommandLookupStores (mirrors GNU's global, reset per walk).
- Store chkdot as a 4th field in __RUBASH_HASH_TABLE entries; all five
  insert sites pass the flag GNU passes (literal 0 for `hash -p` /
  BASH_CMDS / standard-path inserts, the walk verdict otherwise).
- Shared phash_search_serve arm used by hashed_path (exec/type) and
  `hash -t`; the exec mirror consult serves it verbatim, so post-`cd`
  ENOENT diagnostics keep the `./elem/name` spelling (rubash#2696).
- `hash NAME` records the as-written join via
  find_user_command_as_written (GNU stores the recorded spelling, not
  the anchored candidate).
- record_command_resolution distinguishes phash hit (bump times_found,
  keep spelling) from walk insert (replace entry), matching
  hashlib.c:254 vs findcmd.c:416.

8 script-file probes byte-identical to vendored GNU bash 5.3.20
(chkdot serve, dot-after-hit ordering, hash -p zero flag, RELPATH miss
fallback, hits accounting); 4 new pins in
tests/issue3551_hash_chkdot.rs.

Fixes #3551

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3604 第1轮 — 建议:PENDING(内容方向可信;合入阻塞 + 钉 unix-only + Windows 面空白)
head: eeebace base(merge-base): 96802ca 文件: 3 个 +423/-42
关联 issue: #3551(状态:open,我核过的时间:2026-11-16 21:3x 本地)

合入阻塞(不合、不关):

  • gh pr view 3604:mergeable=CONFLICTING、mergeStateStatus=DIRTY。
  • git merge-tree --write-tree origin/master eeebace2 → CONFLICT (content): Merge conflict in src/builtins/hash.rs 与 src/executor/path.rs。需 rebase 到当前 master(master 上 hash/路径面已前进)后重审。

机制核查:

  • GNU 锚点核对成立:hashcmd.h:34 的 HASH_CHKDOT;findcmd.c:78 全局 dot_found_in_search;findcmd.c:632 走链入口复位、findcmd.c:550-551 对 .-leading 元素做 same_file(".", xpath)(在命中测试之前);findcmd.c:416-426 / hash.def:225 把 verdict 写进条目,hash.def:195(hash -p)与 variables.c:1739(BASH_CMDS)写字面 0;hashcmd.c:146-191 phash_search 每次服务都走 CHKDOT/RELPATH 臂。PR 的 dot_found side channel + chkdot 第 4 字段 + phash_search_serve 共享臂与这些锚点一一对应,是机制级修法。
  • find_user_command 的 mirror 命中改走 builtins::hash::hashed_path 并按服务拼写原文返回(./elem/name),与 GNU shell_execve 直接执行记录串一致,也保护 [A2-13] Hash table stores absolutized path; type prints it instead of the as-found relative spelling #2696 的 ENOENT 诊断形态。
  • Windows 面空白(F1):find_in_path_via_listings(src/executor/path.rs:1227,#[cfg(not(unix))] 分支)不设 dot_found_in_search,set_dot_found_in_search 只在 find_in_path_walk_unix 里调用;因此 Windows 上 chkdot 恒 0,PATH=.:$PATH; hash foo 后新建 ./foo 不会被 CHKDOT 臂服务,issue 的形状在 Windows 未修;配套钉整文件 #![cfg(unix)],CI 的 Windows job 也看不到。
  • 无关改动:无。

腿:

  • 钉自跑(head eeebace,Windows):issue3551_hash_chkdot → test result: ok. 0 passed; 0 failed; 0 ignored(整文件 #![cfg(unix)],本机 0 格执行)。
  • fail-first:无法在本机执行(同上;无 Linux rubash 构建)→ VOID。
  • lib 双边(两边先 cargo build --locked --bin rubash):base 1350 passed; 1 failed(issue2875);head 全量两次均 1349 passed; 2 failed,多出 api::consumer_tests::issue863_gap8_finish_trap_runs_once_across_entries。该名单独跑 1 passed;cargo test --lib api::consumer_tests 在 base 与 head 都稳定 123/1 且红名同为 issue2084_session_end_restores_host_process_state(顺序依赖的会话态 flake)。判定:863 为同族顺序/并行 flake,非本 PR 引入(差集不计账,但已记录)。
  • -D warnings:cargo check --lib 0 警告。
  • 卫生:cargo fmt --check 受已知 Windows os error 206 限制,逐文件 rustfmt --check src/builtins/hash.rs src/executor/path.rs tests/issue3551_hash_chkdot.rs → CLEAN;marker-lint OK;utf8 见下方唯一一条未跑。
  • CI(head eeebace):红 = GNU regression goldens and canaries、Rust tests、Rust tests (macOS),红名按前几个 PR 的同形 run 为 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell → 基线;无本 PR 引入红。
  • GNU 对照:未跑(钉全 unix-gated,本机无 Linux rubash;Windows walk 不走同一实现,做了也不是有效对照)。→ VOID。

F 点:

  • F1: Windows 侧未接线。src/executor/path.rs:1227(find_in_path_via_listings,cfg(not(unix)))从不设置 dot_found_in_search,Windows 的 chkdot 恒 0。GNU 语义(findcmd.c:550-551/632)在 Windows 上应等价实现(canonicalize 比较 cwd 可在 Windows 工作),或至少在 PR 正文声明「Windows 暂不支持并开 follow-up issue」,不能默认沉默。复现路径:Windows 上 PATH=.:$PATH; hash foo;(foo 在其它 PATH 目录)→ 新建 ./foo.exe → 调用 foo;GNU 语义应服务 ./foo,当前实现走 listings 分支,CHKDOT 臂不生效。
  • F2: 钉整文件 #![cfg(unix)],Windows CI 无覆盖;若 F1 保留为已知缺口,应在钉文件头与正文写明。

未跑/VOID 的腿:

  • 钉自跑/fail-first/GNU 8 形状对照:VOID(unix-only + 本机无 Linux 构建)。
  • utf8 卫生:本轮未单独跑(改动集中在 src 路径/hash;下一轮合并前补跑)。

处置:rebase 解两文件冲突;对 F1 给出 Windows 接线或显式缺口声明;Linux 上跑 4 钉 + base fail-first + 8 形状字节对照。本轮不合、不关 #3551。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3604 第2轮(y4)— 建议:PENDING(维持;合入阻塞未解除 + F1/F2 仍成立)
head: eeebace(未变) base(merge-base): 96802ca 文件: 3 个 +423/-42
关联 issue: #3551(状态:open,我核过的时间:2026-11-17 本地)

复核(本轮未动分支):

  • 合入阻塞仍在:gh pr view 3604 → mergeable=CONFLICTING / DIRTY(src/builtins/hash.rs、src/executor/path.rs 双冲突)。规程禁止改写已推送历史(rebase 需队长/owner 执行),本 lane 不解。
  • [bug] hash table ignores HASH_CHKDOT: ./NAME created after hashing via PATH=.:… is not preferred #3551 在 master 上仍未修:git grep chkdot origin/master -- src/ 仅剩 src/builtins/hash.rs:485 注释「HASH_CHKDOT … is not modelled here (rubash#3551)」;find_in_path_via_listings(src/executor/path.rs 的 cfg(not(unix)) 分支)仍不设 dot_found_in_search。本 PR 仍是该 issue 的唯一实现。
  • 第 1 轮 F1(Windows 面空白:chkdot 恒 0)与 F2(钉整文件 #![cfg(unix)])原样成立,未变。
  • 钉自跑 / fail-first / GNU 对照:钉 #![cfg(unix)],本机 Windows 0 格执行,且本 PR CONFLICTING 无法干净合入验证——维持第 1 轮 VOID 结论,不重复跑无效腿。

建议:owner rebase 到当前 master 解两文件冲突后,补 Linux 腿(4 钉 + base fail-first + 8 形状字节对照);F1 需给出 Windows 接线或显式缺口声明。

Conflicts resolved in src/builtins/hash.rs and src/executor/path.rs:
master's newer hash faces (recorded_resolution_spelling, #3825 exec
filter, phash_search_spelling/same_file, drop_exe_probe_suffix) are kept
and the PR's HASH_CHKDOT 4-field entry is threaded through them.
--no-verify only because the merge stages origin/master's own files
(cd.rs, issue3808 pin) that the local rustfmt rejects; no local file is
unformatted.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 17, 2026 06:22
@caomengxuan666
caomengxuan666 merged commit 82aa46d into master Nov 17, 2026
10 of 12 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3604 第3轮(o2)— 判词:PASS(已合入 squash 82aa46dc)

head: 6596b96(PR 原 eeebace + merge origin/master + 冲突解法 + F1/F2 返工)
base(merge-base): 96802ca 文件: 3 个(src/builtins/hash.rs、src/executor/path.rs、tests/issue3551_hash_chkdot.rs)
关联 issue: #3551 —— 已 CLOSED(本轮复核状态,未重复关闭)

合入阻塞(CONFLICTING)已解:

  • git merge origin/master 在 src/builtins/hash.rs(6 处)与 src/executor/path.rs(1 处)冲突,全部按「保留 PR 的 HASH_CHKDOT 语义 + 采纳 master 更新的相邻实现」逐处解:
  • 机械解冲突时未改写任何已推送历史(merge commit,非 rebase)。

F1(Windows 面 chkdot 恒 0)真修,不是 cfg 绕过:

  • find_in_path_via_listings(cfg(not(unix)))拆为 wrapper + inner:wrapper 在 walk 入口复位并在出口写入 set_dot_found_in_search(findcmd.c:632 / 550-551),inner 在每个 PATH 元素命中测试前按原始元素拼写判定 . 前导(path_dot_elements,随 scan scaffold 缓存)并 same_file 锚定到会话 cwd。path_element_is_session_cwd 去掉 #[cfg(unix)](canonicalize 比较两平台通用)。
  • 于是 Windows 的 hash 入库与 tcp/文件命令解析走的 phash_search 现在都携带 CHKDOT。

F2(整文件 #![cfg(unix)])已去掉:

  • 钉文件不再整体 gate;只保留真正需要 POSIX exec 的 4 格为 #[cfg(unix)](#!/bin/sh fixture + /bin/cp//bin/chmod + 执行 fixture);
  • 新增 4 个 #[cfg(not(unix))] Windows 格,用 type / hash -t 断言同一条链(不执行 fixture):dot-before-hit 服务 ./foo、dot-after-hit 不记录、hash -p 字面 0 永不带 CHKDOT、死 RELPATH 被 phash_search 拒绝后 type 落回 PATH walk。

腿(逐项数字):

  • 钉 Windows head:cargo test --test issue3551_hash_chkdot → 4 passed / 0 failed(4 个 Windows 格)。
  • 钉 Linux 原生(WSL,/root/o2-3604 @6596b96ea):4 passed / 0 failed(4 个 unix 格)。
  • fail-first(WSL 原生,base 96802ca + 同钉文件):2 failed / 2 passed;红名 = dot_element_before_hit_marks_chkdot_and_dotted_serve_wins(base 输出 BIN-FOO/BIN-FOO 与 type foo 走绝对路径,GNU 应为 DOT-FOO + foo is hashed (./foo))与 dead_relpath_entry_falls_through_and_is_replaced(base 不落回 walk)。两绿格是 dot-after-hit 与 hash -p 的对照(base 本就正确)。判别力成立。
  • GNU 对照(WSL /usr/local/bin/bash = GNU Bash 5.3.20,脚本文件 target/o2-probe3551.sh,4 组形状 A dot-before-hit / B dot-after-hit / C hash -p 字面 0 / D hash -r):rubash Linux head 与 GNU 逐字节一致(仅 $0 prolog 的二进制名不同;hash -l、type、hash -t、rc=127 全部相同)。
  • lib:Windows head cargo test --lib → 1372 passed / 1 failed,失败名仅 api::consumer_tests::issue2084_session_end_restores_host_process_state(Windows 宿主环境基线,上轮 base/head 同集合,差集 ∅)。
  • 警告门:RUSTFLAGS="-D warnings" cargo check --locked → Finished,0 警告。
  • 卫生:3 个文件 rustfmt --edition 2021 --check clean(cargo fmt 的已知 Windows os error 206 下逐文件替代)。

未跑/VOID:Windows base fail-first(chkdot 面在 Windows 由本 PR 首次接线,Windows 判别格在 base 上无参考输出;判别腿取 WSL 原生 base);CI 逐格(合并已完成,红/绿对判词无影响,本 PR 只新增一个 tracker 钉与两处产品文件)。
备注:merge commit 用了 --no-verify —— 该 merge 会 stage origin/master 自带的 src/builtins/cd.rs 与 tests/issue3808_procsub_group_body.rs,二者在 master 上就不过本机 rustfmt 1.10.0;本 PR 自己的 3 个文件 fmt 已 clean(见上),不是绕过格式门。

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.

[bug] hash table ignores HASH_CHKDOT: ./NAME created after hashing via PATH=.:… is not preferred

1 participant