Skip to content

[Compat][quoting] 未加引号参数中的反斜杠被改写为 //,破坏原生 exe 收到的 Windows 路径 #60

Closed

Description

@caomengxuan666

[Compat][quoting] 未加引号参数中的 \ 被改写为 //,破坏传给原生 exe 的 Windows 路径

复测环境:Windows Server 2022 x64,winuxcmd 0.17.1 自带 winuxsh。
复测方法:gcc 编译 argvdump.exe 直调 + python subprocess CreateProcess 双基线对照。

现象

未加引号的参数里,反斜杠 \ 会被改写成双正斜杠 //;引号内完好:

$ argvdump.exe C:\Windows\System32 'C:\Windows\System32' "C:\Windows\System32"
1:[C://Windows//System32]     ← 未加引号:被改写
2:[C:\Windows\System32]       ← 单引号:完好
3:[C:\Windows\System32]       ← 双引号:完好

实际踩坑案例

where.exe /R C:\Windows\System32 notepad.exe
# ERROR: Invalid directory specified
# 实际收到 C://Windows//System32,where 对目录校验严格直接拒绝;
# 同一命令经 python subprocess(绕过 winuxsh 解析)执行成功,exit=0

icacls <file> /grant "Administrators:(F)"
# 巧合成功:Win32 API 容忍 C://Users//... 形式,但 icacls 回显的路径已被改写

cmd //c "..."   # 双斜杠形式失效(cmd 收到字面 //c 只打印 banner);单斜杠 cmd /c 正常

相对路径不受影响:w2.exe /R . notepad.exe 在目录内执行正常。

影响

  • 所有"命令行里裸写 Windows 绝对路径"的场景都会中招;部分程序(icacls)因 Win32 路径容忍性侥幸可用,严格校验的程序(where /R、需要真实反斜杠语义的)直接失败;
  • 用户很难意识到是 shell 改写了参数——报错来自目标程序,且加不加引号结果不同,排查成本高;
  • 与 MSYS2 的 MSYS_ARG_CONV 问题类似,但本改写只针对 \ → //,连 POSIX 路径语义都对不上,属于纯破坏性转换。

建议

  1. 未加引号的 \ 不做任何替换(优先修复);
  2. 若确需路径转换,应仅针对"看起来像 POSIX 绝对路径(/foo)且目标为 MSYS 类工具"的场景,且转换失败时保留原样;
  3. 文档中明确 quoting 规则与转换范围,便于用户规避。

附:同日复测其余项结论(详见 wpm-source/docs/rubash-issue-draft.md)

  • 已修复:引号内 */? 占位符替换、原生 exe --长选项 拦截、/CN=test 前缀路径转换 ✅
  • 撤回:pwsh -File 数组绑定两条,与原生 CreateProcess 行为一致,非 bug
  • bash 为自家 shim,-n 等 flag 不透传属已知设计,不作为缺陷跟踪

Activity

  1. caomengxuan666 commented on Aug 21, 2026

    @caomengxuan666
    MemberAuthor

    Resolved by b5e3f7b (now included in origin/master): native Windows argument handling preserves literal backslashes and repairs only the unambiguous host-rewritten drive form. Focused regression: src/executor/path.rs windows_external_arguments_repair_host_rewritten_drive_backslashes plus the native argv literal tests. The compatibility evidence/docs runner was published in cd87313. Closing this issue because its reported root cause is addressed and covered by focused tests.

  2. added
    bug
    area:path
    gnu-baseline
    on Oct 17, 2026
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

    area:pathbuggnu-baseline

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions