Repository navigation
fix(hash): re-validate relative hash entries on every read (Refs #3359) - #3554
Conversation
GNU hashcmd.c:126 phash_search is the single read of a remembered location for execution (findcmd.c:365 search_for_command), type / command -v (type.def:353) and hash -t (hash.def:284). For a stored relative path (HASH_RELPATH) it serves the ./-prefixed form when executable and answers NULL when the stored ./path's directory is the cwd and the file is gone (hashcmd.c:146-187), so the lookup re-walks PATH. rubash applied that rule only to hash -t and served the stored spelling unvalidated everywhere else; `hash NAME` also stored the cwd-anchored path instead of the search's as-written join (hash.def:213-225 add_hashed_command). - builtins::hash::phash_search / phash_search_spelling: one shared implementation, probes anchored at the session cwd. - path::find_user_command's hash-mirror consult goes through it; a refused entry drops the stale PATH-scan memo and walks PATH. - type/command -v describe faces read through phash_search. - record_command_resolution overwrites a refused entry (phash_insert, times_found = 1) instead of bumping it. - `hash NAME` records recorded_resolution_spelling and syncs the mirror. Also rustfmt tests/d11_pipeline_squote_carrier_regressions.rs, which landed unformatted on master (#3511) and fails the pre-commit check. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…3359) Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
【WIN-AGENT-AUDIT】 PR #3554 第1轮 — 建议:PENDING(缺腿) 机制核查:
腿:
残差疑点(需 Linux oracle 复核,未计入判词):
未跑/VOID 的腿:
|
|
【WIN-AGENT-REWORK】 PR #3554 第2轮 — 建议:PASS(缺腿补齐 + 两残差疑点复核完毕) 本轮补腿(WSL Linux /root/rubash-wsl,CARGO_INCREMENTAL=0,cargo test --locked -j 2):
两残差疑点的 Linux oracle 复核(LF 脚本文件,GNU /usr/local/bin/bash 5.3.20 vs rubash head,target/probes-3554/case.sh):
未动代码;其余腿按第1轮审计记录全绿。判词翻 PASS,按协议 squash 合并。 |
|
【WIN-AGENT-REWORK】补充记录(合并阻塞) 判词 PASS 不变,但 |
# Conflicts: # src/builtins/hash.rs
|
【WIN-AGENT-REWORK】 PR #3554 第3轮 — 建议:PASS(冲突已解 + 腿复核) 冲突解(owner 授权 merge origin/master):
合并头复核腿:
判词 PASS 维持,按协议 squash 合并。 |
…g (Refs #3845) (#3847) find_user_command's hash-mirror consult handed phash_search's stored string to callers verbatim as a PathBuf. The hash table keeps the shell-domain display spelling (/d/..., ./elem/name) for `hash -t` fidelity; on unix that string already is the filesystem path execute_cmd.c:6133 shell_execve execve()s, but on Windows it is not spawnable — Command::new ENOENTs and the diagnostic escapes to the shell's stderr, e.g. `cat cap4 | wc -c` inside a command substitution after any earlier `cat` run recorded the entry (golden issue1230). Introduce: #3554 (46bb796) replaced `return Some(path.clone())` — the mirror's fs path — with the verbatim served spelling for the CHKDOT/RELPATH re-validation arm. #3631 is innocent: the parent tree (9148457) reproduces the leak identically. Return shell_path_to_windows(served) instead — the same funnel record_command_resolution used to build the mirror. It is the identity on unix, maps /d/... to D:\..., and keeps ./elem/name relative so the post-cd ENOENT re-resolution of rubash#2696 is preserved. The checkhash probe now stats the real file too. Pin: executor::path::tests:: hash_consult_returns_spawnable_fs_path_for_display_spelling (red before, green after). Generated with [Devin](https://devin.ai) Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Fixes #3359
修了什么
如果命令是经相对 PATH 条目(
PATH=.:…)记进哈希表的,文件删掉后 rubash 仍原样给出旧拼写:执行报./mycmd/<TMP>/./mycmd: No such file or directory,type、command -v、hash -t仍报已哈希。GNU 的phash_search在每次读表时复核相对条目:./形可执行就给出;否则若存的路径以.开头且所在目录就是 cwd,则返回 NULL,查找回落到 PATH 漫游(command not found,127)。表项本身保留,直到漫游在别处命中时被覆盖。src/builtins/hash.rs:新增共享实现phash_search(env, name)/phash_search_spelling(path, env)。它取代原先hash -t私有的phash_search_target,探针改为锚定会话 cwd(G-02)。src/executor/path.rsfind_user_command:查哈希镜像就是走一遍 phash_search。表项被拒时,丢掉该名的 PATH 扫描旧备忘,改走 PATH 漫游。checkhash 复核作用在 phash_search 给出的值上,与 GNU 顺序一致。src/executor/lookup_paths.rs(command_path/command_paths)、src/executor/type_describe.rs:type、command -v的读面改走phash_search。record_command_resolution:若表项被 phash_search 拒绝(即本次结果来自漫游),按phash_insert覆盖并把 times_found 置 1,不再给旧项计数。hash NAME:记录recorded_resolution_spelling(与执行记录走同一漏斗,[A2-13] Hash table stores absolutized path; type prints it instead of the as-found relative spelling #2696),并同步镜像。原先存的是锚定会话的绝对路径,后续读面因此看不到它的相对性。删了什么
hash -t私有的phash_search_target(已并入共享实现)。hash NAME的绝对路径存储,以及"find_user_command 已写缓存,所以不需要镜像"这条旁路。附带:
tests/d11_pipeline_squote_carrier_regressions.rs在 master(#3511)合入时未格式化,导致 pre-commit 的 rustfmt 检查失败。本 PR 对它跑了 rustfmt,只改格式;#3531 带有同一改动,两边字节相同。GNU 依据
hashcmd.c:126 phash_search():HASH_RELPATH 分支hashcmd.c:146-161(./形可执行即给出)、hashcmd.c:176-187(same_file(".", dir)成立则返回 NULL);hashcmd.c:115记 RELPATH 标志。findcmd.c:365search_for_command 先调 phash_search;返回 NULL 时findcmd.c:400-426漫游,并以phash_insert(..., found=1)覆盖。builtins/type.def:353describe_command 与builtins/hash.def:284list_hashed_filename_targets 同样读 phash_search。builtins/hash.def:213-225add_hashed_command:phash_insert(w, find_user_command(w), dot_found_in_search, 0),存的是搜索时的原样拼接。验证
回归测试
tests/issue3359_hash_relative_path_revalidate.rs:4 个测试,#![cfg(unix)],期望值是 GNU 5.3.20 跑同一脚本的 stdout/stderr,逐字节比对。议题种子
seed_r93b2.sh(Linux):修后 10/10 PASS(GNU 10/10)。同族 stem 在 Linux 全部通过:issue1360 2/2、issue1361 6/6、issue1362 2/2、issue1368 2/2、issue1382 3/3、issue1489 1/1、issue1551 14/14、issue1648 4/4、issue2066 9/9、issue2514 6/6、issue2518 2/2、issue2696 2/2、issue2700 2/2、issue2736 9/9、issue2972 16/16、issue3020 9/9、issue3083 4/4、issue3147 10/10、type_p_flag_regressions 13/13;
--lib hash5/5、--lib lookup5/5。Windows:同一组 stem 修前修后的失败测试名单逐个相同,无新增失败;
--lib hash6/6、--lib lookup8/8。既有的失败共 26 行 FAILED,都是本机 Windows 环境下修前就存在的(issue1361 5、issue1489 1、issue1551 9、issue2700 1、issue2972 3、type_p_flag 1 等)。Owed
recorded_resolution_spelling的 as-found 分支只在cfg(unix)下生效,[A2-13] Hash table stores absolutized path; type prints it instead of the as-found relative spelling #2696 只修了 unix 面),所以 RELPATH 复核在 Windows 上不会触发,种子在 Windows 上仍有 4 个 FAIL。要不要把 as-found 拼写扩展到 Windows,属于 Windows 人格的裁决,本 PR 不动。.条目排在命中目录之前时优先./NAME)未建模,已另开 [bug] hash table ignores HASH_CHKDOT: ./NAME created after hashing via PATH=.:… is not preferred #3551。type.tests。