Skip to content

fix(cd): refuse chdir into directories without the search bit (Refs #3788) - #3797

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3788-cd-no-search-permission
Nov 17, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3788-cd-no-search-permission

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3788

根因:会话 cwd 移动(G-02)从不 chdir 进程本体,探针是 canonicalize + is_dir;两者对缺 search 位的目录都成功——路径解析只要求父分量有 search 位,只有 chdir 本身才查目标位。于是 cd/pushd 对一次从未发生的移动报成功(rc 0、PWD/DIRSTACK 已更新)。GNU builtins/cd.def change_to_directory 做真正的 chdir(cd.def:600/641),以 EACCES 拒绝且 cwd 不变;失败尾用 chdir 的 errno 报(cd.def:427)。

修法:一个共享探针 executor::path::probe_directory_for_chdir(canonicalize + 目录判定 + 对解析后目标的 access(2) X_OK),用于:cd 移动探针;CDPATH 命中判定(无 search 位的候选落到下一单元,cd.def:353-388);cdable_vars 守卫(无 search 位的操作数不再挡住变量步,cd.def:397-405);pushd 操作数门与错误文本;popd 的内层 cd;pushd 换位/旋转(GNU pushd.def change_to_temp -> cd_to_string -> cd_builtin);$(cd X && pwd) 快捷路径。

回归钉:tests/issue3788_cd_no_search_permission_regressions.rs,覆盖 cd 与 pushd、模式 000/222/444(拒绝)与 100/111/555(成功)、相对/绝对/symlink/嵌套路径、CDPATH 落空、cdable_vars、comsub 快捷路径、pushd 旋转/换位到无 search 位条目;探针以非特权用户跑(root 会绕过权限位),无可用非特权用户时跳过。

UNVERIFIED-BY-CAPTAIN

本 PR 删除了什么:

  • 无产品行为删除:仅把 cd/pushd 的移动探针从 canonicalize + is_dir 收紧为等价于 chdir 的判定;无 API、无公开面、无文件删除。
  • 删除了两处重复的 not_a_directory_error 小函数(cd.rs、pushd.rs),其职责并入 executor::path::probe_directory_for_chdir。

…3788)

Root cause: the session-cwd moves (G-02) never chdir the process;
their probe was canonicalize + is_dir, and both succeed on a
directory without the search (execute) bit -- path resolution needs
search permission only on the PARENT components, while only chdir
itself checks the target. cd/pushd therefore reported success (rc 0,
PWD/DIRSTACK updated) for a move that never happened. GNU
builtins/cd.def change_to_directory performs a real chdir
(cd.def:600/641) and refuses with EACCES, leaving the cwd unchanged.

Fix: one shared probe, executor::path::probe_directory_for_chdir
(canonicalize + directory + access(2) X_OK on the resolved target),
used by cd's move probe, the CDPATH hit test (a no-x candidate now
falls through to the next unit, cd.def:353-388), the cdable_vars
guard (a no-x operand no longer blocks the variable step,
cd.def:397-405), pushd's operand gate + error text, popd's inner
cd, pushd swap/rotation (GNU pushd.def change_to_temp ->
cd_to_string -> cd_builtin), and the $(cd X && pwd) fast path.
Regression nails in
tests/issue3788_cd_no_search_permission_regressions.rs cover cd and
pushd, modes 000/222/444 (refuse) vs 100/111/555 (succeed),
relative/absolute/symlink/nested paths, CDPATH fallthrough,
cdable_vars, the comsub fast path, and pushd rotation/swap onto a
no-x entry; probes run as an unprivileged user (root bypasses the
bits) and skip when no such user is available.

UNVERIFIED-BY-CAPTAIN

本 PR 删除了什么:
- 无产品行为删除:仅把 cd/pushd 的移动探针从 canonicalize +
  is_dir 收紧为等价于 chdir 的判定;无 API、无公开面、无文件
  删除。
- 删除了两处重复的 not_a_directory_error 小函数(cd.rs、pushd.rs),
  其职责并入 executor::path::probe_directory_for_chdir。
caomengxuan666 added a commit that referenced this pull request Nov 16, 2026
The 4 pins (funsub comment/heredoc x3, nested comsub in brace
expansion x1) need the REAL lexer layer: no-alias isolation probes
show base and fixed binaries behave identically on all four, so the
alias pre-scan fix in this PR cannot turn them green. They now live
in rubash #3823 (pin definitions + GNU anchors + the #3808/#3797
merge gate). This stem now holds the 11 pre-scan-layer pins only
(11/11 green on X299, two rounds consistent).

Refs #3813, #3823
caomengxuan666 added a commit that referenced this pull request Nov 17, 2026
… as opaque (Refs #3813) (#3821)

* test: add fail-first regression pins for alias comsub comment quote (Refs #3813)

Alias T='{ f() {' + $(...) holding a #-comment with an odd number of
apostrophes fails to parse (rc=2, unexpected end of file from `{');
GNU is rc=0. Pins cover the issue parity table (p0-p4), comment after
$(, nested/dquoted/case comsub, alias-after-comment, heredoc in
comsub, nested comsub in ${...}, funsub comment/heredoc faces, and
the literal-$# / mid-word-# / ${...}-# controls that must keep
passing. Fail-first: expected red on base 969230b; fix follows.

* fix(parser): alias pre-pass treats quotes in comsub comments/heredocs as opaque (Refs #3813)

skip_dollar_paren delegated to skip_parenthesized_unit_corrected
(comments at token boundaries and heredoc bodies opaque, case
`)\`' resolved like the body parser); skip_dollar_brace delegates
nested $(...) the same way; skip_funsub_body gains a #-comment arm
(token-boundary gated) and a << heredoc arm. GNU: parse.y:3631
shell_getc, parse.y:4451 parse_comsub, make_cmd.c:512. Same defect
class as #2033's pre-pass walkers; these three helpers were the
residual.

* style: rustfmt alias_stream.rs + issue3813 nails (Refs #3813)

rustfmt --check (X299 leg) flagged 4 hunks; whitespace-only, no
semantic change: one guard join, one assert! join, one let split,
two control tuples expanded (trailing commas per rustfmt).

* test: move 4 real-lexer pins out of issue3813 stem to #3823 (Refs #3813)

The 4 pins (funsub comment/heredoc x3, nested comsub in brace
expansion x1) need the REAL lexer layer: no-alias isolation probes
show base and fixed binaries behave identically on all four, so the
alias pre-scan fix in this PR cannot turn them green. They now live
in rubash #3823 (pin definitions + GNU anchors + the #3808/#3797
merge gate). This stem now holds the 11 pre-scan-layer pins only
(11/11 green on X299, two rounds consistent).

Refs #3813, #3823

---------

Co-authored-by: 曹梦轩 <[email protected]>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【Y3-AUDIT】续作记录(第1轮进行中)

  • 动作:修 darwin/linux cross-target 编译失败——tests/issue3788_cd_no_search_permission_regressions.rs 内 9 处 Some(&format!("PWD=…")) 产生 Option<&String> vs Option<&str> E0308(该文件 #![cfg(unix)],Windows 本地编译不到,故 CI 才暴露);另清理未使用的 Path import;rustfmt 归一化(pre-commit 强制)。
  • commit: 609f24a test: make issue3788 unix assertions Option<&str>-typed (Refs #3788);新 head: 609f24a
  • 产品代码未动;机制核查与腿数据见本轮报告评论。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【Y3-AUDIT】续作记录 第2轮 — 钉期望修正(产品代码未动)

  • CI census(head 609f24a,Linux 实跑)暴露 issue3788 stem 2 红:issue3788_pushd_no_search_permission_refused、issue3788_pushd_rotation_onto_unsearchable_entry_refused。逐条对 WSL GNU bash 5.3.20(1) nobody 实跑(脚本 target/devin-dispatch/probes/gnu-3788-exact.sh、gnu-3788-rot2.sh)后定性:两处均为钉期望错误,非产品缺陷——
    1. dirs 在 HOME=work 下把栈顶缩写为 ~(GNU 同);钉误期望全路径。rubash 实际输出 rc=1 / ~ / PWD=<work> 与 GNU 逐字一致。
    2. 旋转脚本 pushd d555; pushd d111 中第二条相对路径在 GNU 下同样失败(cwd 已是 d555,d555/d111 不存在,p2=1)——作者意图的栈 [d111,d555,work] 根本没建成;GNU pushd +1 实际 rc=0 转到 work,rubash 输出逐字一致。修正:pushd ../d111 建堆 + chmod 555 d555 前置恢复(part1 的 chmod 000 会留到 part2)。GNU 复核修正后语义:pushd +1 撞上 000 目录 → rc=1、pushd: <abs>: Permission denied、PWD 留 d111、栈已旋转——与钉断言吻合。
  • commit: e17a218;新 head: e17a218(已推送复核一致)
  • 遗留验证腿:census 重跑中——pushd +N 旋转臂与 bare-swap 臂的 EACCES 拒绝为本轮唯一未被 GNU 对照覆盖的产品路径(probe_stack_dir 已上两臂,机制同 cd 探针)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【Y3-AUDIT】PR #3797 第1轮 — 建议:PASS(含两轮续作:609f24abc 编译修复 + e17a218 钉期望修正)
head: e17a218 base(merge-base): c3bf91e 文件: 6 个 +726/-46(续作后净)
关联 issue: #3788(open)

机制核查:

  • 根因属实:G-02 会话 cwd 移动不 chdir 进程本体,探针=canonicalize+is_dir;二者对缺 search 位目录均成功(路径解析只要求父分量 search 位),而 GNU builtins/cd.def change_to_directory 做真 chdir(cd.def:600/641)以 EACCES 拒、errno 尾报(cd.def:427)。
  • probe_directory_for_chdir(executor/path.rs:~8415):canonicalize+is_dir+unix access(2) X_OK(目录版 file_is_executable,findcmd.c file_status 同款 real-uid 判定);Windows 桩恒 true(无 unix 权限位语义)——机制正确,root 由 access(2) 自然放行与真 chdir 一致。
  • 覆盖面与 GNU 一致:cd 移动探针、CDPATH 命中(cd.def:353-388 落空下一单元)、cdable_vars 守卫(cd.def:397-405 仅当操作数 chdir-able 时阻断变量步)、pushd 操作数门+错误文本(ENOTDIR/EACCES/ENOENT 三分)、pushd 换位/旋转(change_to_temp→cd_to_string→cd_builtin)、popd 内层 cd、$(cd X && pwd) 快捷路径——均按 GNU 判定链落点。
  • 无无关改动;无桥接层;标题/正文/commit 仅 Refs #3788。

腿:

  • 钉自跑:Linux census(head e17a218)issue3788 stem 6/6 全 PASS:cd_no_search_permission_refused、pushd_no_search_permission_refused、pushd_rotation_onto_unsearchable_entry_refused、cdpath_skips_unsearchable_candidate、cdable_vars_tried_after_unsearchable_operand、comsub_cd_pwd_fast_path_refused(run 44016473317 job 133815508585,序号 8997-9005/10563)
  • fail-first:钉面即 issue 面(无 search 位被误放行);Unix-only,本地 Windows 无法实跑——以 Linux census 实跑为准,产品修复前该 stem 在 base 上必红(canonicalize+is_dir 对 000 目录返回 Ok)
  • lib 双边:产品改动集中 unix 权限路径(Windows 桩恒 true,行为不变);Windows cargo test --lib 各轮 1360+/1(仅已知 issue2084 环境 flake);CI Rust tests/Rust tests (macOS)/Shell/CLI/cross-target×2/niubash 全 PASS
  • -D warnings / 卫生:cross-target darwin+linux/android 编译 PASS(原 E0308×9+unused import 已修);rustfmt 归一(pre-commit 强制);marker/utf8 卫生前轮净
  • CI:census 38 红 stem vs master 37——差集仅 +issue1902(已知 flake);goldens = 基线同名对(issue_753::case_9 + upstream_suite_slice_snapshots)→ 无本 PR 账
  • GNU 对照:WSL bash 5.3.20(1)-release nobody 实跑(setpriv,脚本 target/devin-dispatch/probes/gnu-3788-exact.sh/gnu-3788-rot2.sh/gnu-3788-pushd-nobody.sh):pushd 000→Permission denied rc=1 dirs=~;修正后旋转脚本 pushd +1 撞 000→rc=1 pushd: <abs>: Permission denied PWD 留 d111 栈已旋转——与钉断言及 rubash census 实跑结果一致

续作记录:

  • 609f24a test: make issue3788 unix assertions Option<&str>-typed(修 cross-target E0308×9 + unused Path import)
  • e17a218 test: correct issue3788 pushd nail expectations to GNU dirs/rotation semantics(dirs 的 ~ 缩写期望 ×2;旋转脚本 pushd d111→pushd ../d111 ×2 + part2 chmod 555 d555 前置)

F 点:无(原 head 两处 CI 编译错与两处钉期望错均已续作消除,census 实跑 6/6 绿)

未跑/VOID 的腿:fail-first 独立 base 构建(unix-only 钉,本地无法跑 unix;以 Linux census head 实跑 + GNU 对照为证)

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 17, 2026 04:31
@caomengxuan666
caomengxuan666 merged commit a297e72 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