Skip to content

realpath -m / readlink -m: a relative .. never goes above the current directory #1908

Done

Description

@ShiomiHC
cd /c/Windows/System32
realpath -m ..
realpath -m ../..
realpath -m ../x
readlink -m ..

WinuxCmd:

/c/Windows/System32
/c/Windows/System32
/c/Windows/System32/x
/c/Windows/System32

GNU coreutils (Git for Windows):

/c/Windows
/c
/c/Windows/x
/c/Windows

Without -m the answer is right (realpath .. prints /c/Windows), and so is an absolute operand (realpath -m /c/Windows/System32/.. prints /c/Windows). WinuxCmd 1.2.1 printed C:\Windows for realpath -m ...

Scripts that resolve a path with realpath -m before checking it (for example, refusing to walk a drive root) get the current directory back for ../.. and let it through.

WinuxCmd 1.2.3 (WinuxCmd-1.2.3-win-x64.tar.gz), Windows 11.

The issue was drafted with Claude and the reproductions were run on the versions above.

Activity

  1. caomengxuan666 commented on Nov 28, 2026

    @caomengxuan666
    Member

    队长分拣:确认本方 bug(回归)(建议 P2;报告人指出的「先 realpath -m 再做路径守卫」被绕过场景属实)。

    两侧实测:

    • GNU coreutils 9.4 oracle(云端,cwd=/home/cmx/oracle):realpath -m .. → /home/cmx;realpath -m ../.. → /home;realpath -m ../x → /home/cmx/x;readlink -m .. → /home/cmx。相对 .. 在 -m 下按词法上行。
    • X299 装机 WinuxCmd 1.2.1 不复现:cwd=C:\Windows\System32 时 realpath -m .. → C:\Windows、realpath -m ../.. → C:\、realpath -m ../x → C:\Windows\x、readlink -m .. → C:/Windows(上行正确;仅 realpath 输出为 native 反斜杠形,与报告人记的 1.2.1 行为一致)。
    • 当前 master 源码与报告人的 1.2.3 实测同形:rust2/crates/winux-cmds/src/canon.rs 的 normalize_lex_native 对相对操作数以空 stack 起步做词法行走,.. 只弹操作数自身的分量、永不弹 cwd 的分量——.. 得 cwd 本身、../.. 仍是 cwd、../x 得 cwd/x,与 1.2.3 输出逐条吻合。

    说明:队长装机只有 1.2.1,未能在装机上实跑 1.2.3 的坏形;坏形由报告人实测 + master 源码路径同形双证。回归窗为 1.2.1 → 1.2.3(rust2 canon 移植波)。

    修复方向:-m 词法行走应以 cwd 的分量作为初始 stack(在盘符根处钳制),使前导 .. 能上行出 cwd;readlink -m 共用同一 canonicalize_operand,一并受益。补钉请带相对 .. 跨出 cwd 的用例(现 gate 的 realpath/readlink TSV 未覆盖此形)。

    — 队长分拣

  2. added
    bug
    compat-verified
    on Nov 28, 2026
  3. caomengxuan666 commented on Nov 28, 2026

    @caomengxuan666
    Member

    Fixed by #1918 (merged 24c6eb6): normalize_lex_native now starts relative -m forms from the cwd components, so .. ascends again; anchor roots are never popped. Verified fail-first both ways with 3 new pins; CI all green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcompat-verified

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions