Repository navigation
fix(pushd): resolve relative targets against the validated cwd (Refs #3396) - #3478
Merged
Merged
Conversation
Fail-first nails for rubash#3396: pushd must resolve a relative target against the real cwd (getcwd), not $PWD. GNU pushd.def:296-302 delegates the Dir operand to cd_builtin, whose change_to_directory (cd.def:522ff) chdirs the operand as-is; bindpwd rebuilds PWD from get_working_directory (common.c:592). Covers PWD unset / empty / stale, ./a, chained ../b, pushd/popd round-trip, dirs -l, the -n raw-store control, and the cd / absolute-target controls. Not yet executed in this lane (no build slot); legs owed to the captain review round.
…3396) normalize_stack_dir joined every relative pushd operand onto the raw $PWD, so 'unset PWD; pushd a' looked up /a and 'PWD=/wrong; pushd a' looked up /wrong/a (rc 1, PWD left empty/stale, stack untouched). GNU pushd.def:296-302 delegates the Dir operand to cd_builtin, whose change_to_directory (cd.def:522ff) chdirs the operand as-is, so the kernel resolves a relative operand against the real cwd, never $PWD (common.c:592 get_working_directory is getcwd); bindpwd then rebuilds PWD from getcwd. Under G-02 the session cwd field is that real cwd, so the base is now validated_logical_pwd (cd/paths.rs, rubash#2143): $PWD while it still names the working directory, the physical session cwd otherwise. Healthy-$PWD behaviour is unchanged; pushd -n (raw store, no cd call) is untouched. Both call sites (Dir arm, pushd - OLDPWD arm) pass the session cwd. Nails: tests/issue3396_pushd_relative_getcwd_regressions.rs (6 tests). Legs owed to the captain review round (no build slot in this lane).
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿(逐项):
F 点:无。 续作记录:无(未动代码)。 未跑/VOID 的腿:Windows 侧钉自跑为预期 VOID(cfg(unix)),已由 WSL Linux 双侧实跑覆盖;其余全跑。 |
caomengxuan666
marked this pull request as ready for review
November 15, 2026 02:11
This was referenced Nov 15, 2026
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.
根因
normalize_stack_dir(src/builtins/pushd/stack.rs)把相对操作数拼到原始 $PWD 上:未设时基为/(查/a)、空时基为空(查/a)、陈旧时基为/wrong(查/wrong/a),于是unset PWD; pushd a报pushd: a: No such file or directory、rc 1、PWD 留空/陈旧、栈不动。GNU 锚点
cd_builtin。change_to_directory:把操作数原样 chdir,相对路径由内核按真实 cwd 解析,与 $PWD 无关。get_working_directory:即 getcwd;bindpwd(cd.def:136-175)据此重建 PWD。validated_logical_pwd,[bug] 逻辑 PWD 未校验是否指代当前目录:伪造/陈旧 $PWD 被 pwd/cd 盲信 #2143)。修法
normalize_stack_dir(dir, env_vars)→normalize_stack_dir(dir, env_vars, cwd),相对基改走validated_logical_pwd;两处调用点(Dir 臂与pushd -的 OLDPWD 臂)传入 session cwd。健康 PWD 下行为不变(基仍是 $PWD 本身);仅未设/空/陈旧时改走真实 cwd。pushd -n(存原始词,不调 cd)不受影响。回归钉
tests/issue3396_pushd_relative_getcwd_regressions.rs:未设/空/陈旧三形、
./a、链式pushd ../b、pushd/popd 往返、dirs -l、-n 控制、cd 与绝对目标控制。期望以 GNU 实测为准(种子 seed_r104a.sh 10/10;扩展形同法探针确认)。本 PR 删除了什么
无。仅改解析基的取值来源,未删除任何公开面、测试或文档。
验证状态
UNVERIFIED-BY-CAPTAIN。钉与修法已写,未在本车道执行:本地构建禁令(写墙间歇 EDQUOT;本轮为 clone 已回收已完工车道 target 约 1.9G)、Simular box 盘满、老服务器 ssh 未恢复、X299 车道直连未通。以下腿欠队长复核轮(X299):新 stem
issue3396_pushd_relative_getcwd_regressions全绿、相邻issue3197/issue3196/issue3336stem、全量 lib 与 base 逐数对齐、RUSTFLAGS="-D warnings" cargo check --locked --lib --bins。静态已过:rustfmt --check、check-utf8-boundary-hygiene.sh、check-marker-literals.py 全 clean;fail-first 依据为裁决预筛实测(rubash 4/10,三 pushd 相对格失败)+ 现尖代码直读。