Skip to content

fix(ldd,date): fold POSIX drive-dialect operands before any open (#1238 #1239) - #1253

Merged
caomengxuan666 merged 3 commits into
mainfrom
fix/1238-1239-drive-dialect
Oct 19, 2026
Merged

caomengxuan666 merged 3 commits into
mainfrom
fix/1238-1239-drive-dialect

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Path-dialect fix wave 2d (#1230 sweep follow-up; precedent #1243/#1245). Closes #1238, closes #1239.

Summary

ldd and date -f both handed the raw operand text to a bare std::ifstream (plus the is_directory probe behind date's "Is a directory" report). Win32/CRT resolve a leading /e against the CURRENT drive, so from a foreign cwd every POSIX drive spelling reported a bogus open failure for a file that exists on the operand's drive - while MSYS opens the same spelling from anywhere.

The operand now folds once through the shared normalize_api_operand boundary at the single open point of each command (load_file for ldd - covering the default, --name and --unused paths; the -f block for date). Error messages keep quoting the operand exactly as typed, like MSYS does. Bare /e (drive root) for date -f now correctly reports "read error: Is a directory" instead of a bogus ENOENT.

Evidence (PS native argv, installed 1.1.14, pre-fix)

probe cwd=C:\Users\cmx cwd=D:\repo MSYS oracle
ldd /e/probe-wd/probe-pe.exe FAIL cannot open FAIL cannot open opens, lists deps
date -f /e/probe-wd/probe-date.txt FAIL ENOENT FAIL ENOENT reads both lines

Post-fix matrix (freshly built binary; E:\probe-wd held a real PE + a date file, removed after):

spelling ldd cwd=C ldd cwd=D date -f cwd=C date -f cwd=D
/e/probe-wd/... PASS PASS PASS PASS
/cygdrive/e/probe-wd/... PASS PASS PASS PASS
/mnt/e/probe-wd/... PASS PASS PASS PASS
bare /e (root) rc=1, operand quoted verbatim (MSYS: "Permission denied") same rc=1 "read error: Is a directory" same
E:\\probe-wd\\... (Windows) PASS PASS PASS PASS

Shadow witness C:\\e, C:\\d, D:\\e: False after every cell (read-only probes) and after cleanup.

Tests

  • ldd.drive_dialect_spellings_resolve_real_pe_from_foreign_cwd - dialect-spells the build tree's own winuxcmd.exe (slash, /cygdrive, /mnt forms) and resolves the real PE from a foreign cwd
  • ldd.drive_dialect_cwd_on_other_drive_resolves_non_pe_probe - probe file only exists at the dialect location; "not a PE executable" (verbatim spelling) proves the fold, "cannot open" would fail it
  • date.date_file_drive_dialect_spellings_read_from_foreign_cwd - all three spellings read the fixture from a foreign cwd
  • date.date_file_drive_dialect_cwd_on_other_drive_reads_file - the audit's exact shape (cwd on a second fixed drive)
  • date.date_file_bare_drive_root_reports_is_a_directory - bare /x keeps the [GNU] directory report with the operand as typed

All regressions synthesize the dialect spelling from the fixture's own drive (land-on-operand-drive, skip when no second fixed drive) and pass on any host.

Validation

  • scripts/build.py (MSVC + CMake + vcpkg, VCPKG_ROOT=D:/vcpkg) builds clean; all ldd/date tests pass via the runner and via ctest
  • Full ctest: 3009 tests; scattered non-overlapping 0xc0000409/env-sensitive flakes on this host pass standalone on re-run and include tests merged by fix(mkdir,ln): fold POSIX drive-dialect operands before any write (#1233, #1234) #1243, and the repeating mktemp_p_cygdrive_dir_outputs_cygdrive_form failure reproduces identically on a pristine origin/main~1 build (3c5d9ad) under cmd-spawned ctest - pre-existing host/env sensitivity, untouched by this branch
  • CHANGELOG [Unreleased] Fixed updated

Read-only fix: no I18N catalog changes (no message text changed).

ldd handed the raw operand to a bare std::ifstream, and the CRT resolves
a leading '/e' against the CURRENT drive: from a foreign cwd every POSIX
drive spelling ('/e/x.exe', '/cygdrive/e/x.exe', '/mnt/e/x.exe') reported
"cannot open" for a file that exists on the operand's drive, while MSYS
ldd opens the same spelling from anywhere (#1238, found by the #1230
sweep; PS probe with native argv).

The operand now folds once through the shared normalize_api_operand
boundary at load_file - the single point every caller opens through,
covering the default, --name and --unused paths. Error messages keep
quoting the operand exactly as typed, like MSYS does.

Regressions dialect-spell the build tree's own winuxcmd.exe (slash,
/cygdrive and /mnt forms resolve the real PE from a foreign cwd) and
probe a TempDir text file from a second fixed drive (open success proves
the fold; the message keeps the verbatim spelling).
date -f DATEFILE opened the file the same way: is_directory and the
std::ifstream open both saw the raw operand text, so a leading '/e'
resolved against the CURRENT drive - from a foreign cwd every POSIX
spelling ('/e/Data/dates.txt', '/cygdrive/e/...', '/mnt/e/...') reported
"No such file or directory" for a file that exists on the operand's
drive, and the directory probe behind the 'Is a directory' report ran
against the shadow path too (#1239, found by the #1230 sweep; PS probe
with native argv, MSYS date oracle reads the same spellings).

The -f operand folds once through the shared normalize_api_operand
boundary before the is_directory probe and the open. The open-failure
messages keep printing the operand as the user typed, like MSYS does;
bare '/e' (drive root) now correctly reports "read error: Is a
directory" instead of a bogus ENOENT.

Regressions dialect-spell a TempDir fixture (slash, /cygdrive and /mnt
forms read the file from a foreign cwd), repeat the audit's exact shape
with the cwd on a second fixed drive, and pin the bare-drive-root
directory report.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Independent code review — verdict: APPROVE-WITH-NITS

Reviewed independently from a fresh detached worktree at f6ba403 (3 commits over base 6e8ea19 — matches the PR header; branch tip confirmed as PR head). git merge-tree against current main (8c19d14) is clean: only CHANGELOG.md auto-merges, no conflicts, no file overlap with #1248/#1252.

Verified (all re-executed; PS native argv; fixture E:\probe-cr1253 created and removed by the review)

  1. ldd call-site closure holds: load_file contains the only std::ifstream in ldd.cpp (ldd.cpp:81); its callers are print_imports (:193, covering the default and --name paths) and the --unused branch (:235). The "embedded dependency" side never opens files — resolve_dll is SearchPathW-only and prints dll => path without reading the resolved DLL. So one fold point covers every open, as claimed.
  2. date -f fold covers probe and open: api_path = normalize_api_operand(date_file) (date.cpp:2388) feeds both the is_directory directory probe (:2390) and the ifstream::open (:2391); all three failure messages quote date_file verbatim. --file/-f resolve to a single operand (no multi-DATEFILE form exists in GNU either). Also checked the fold target for the bare-root edge: fold_drive_dialect_w emits E:\ (absolute root), never drive-relative E:, so no remembered-cwd-on-E: hazard behind the "Is a directory" report.
  3. Baseline reproduces the ticket FAILs: the installed binary (1.1.16 — see nit 3) fails every dialect row exactly as ticketed: ldd → cannot open '<operand>' on all 3 spellings × both cwds, including --name and --unused; date -f → No such file or directory on all 3 spellings × both cwds; bare /e → ENOENT from an own-drive cwd. Windows-form controls pass on both builds. I first verified ldd.cpp/date.cpp are byte-identical across v1.1.14 ↔ 6e8ea19 ↔ v1.1.16, so the installed binary is a valid pre-fix oracle for these two commands.
  4. PR matrix all green: real PE through default / --name / --unused × /e/..., /cygdrive/e/..., /mnt/e/... × foreign + own-drive cwd → full DLL listing, rc 0; non-PE probe → not a PE executable (the load landed on the operand's drive — the fold is witnessed, not just output-matched); date -f reads the fixture on every spelling × cwd; bare /e → date: /e: read error: Is a directory from both cwds; missing-file pins keep the typed spelling (ldd: cannot open '/e/...', date: /e/...: No such file or directory).
  5. Oracle disclosure: this host has no MSYS oracle (no MSYS2/Cygwin, no msys-2.0.dll; the only date.exe under the Niubash tree is WinuxCmd's own). The GNU-side claims are therefore taken from the ticket's documented MSYS behavior and re-verified here only as behavior-reasonableness + landing witnesses (item 4). Flagging this explicitly per review protocol.
  6. Shadow residue zero: C:\Users\cmx\e and E:\e absent after every run; nothing my probes executed creates files. One pre-existing host leftover deserves a note: C:\e (created 16:04 today, before my first probe) — it explains why the baseline bare-/e from a C:-side cwd already printed "Is a directory" (the CRT shadow C:\e exists on this machine). Post-fix behavior is cwd-independent, which is the point of the fix.
  7. Regressions: the 5 new tests (ldd 2 / date 3) pass standalone and in the full run. Full ctest: 3009 tests, 8 failed — cut / find / head / integration / join / ls ×2 / realpath, none ldd or date; all 8 pass in isolation ×4 on this build and ×3 on an identically-configured base build (6e8ea19, separate worktree, same generator/flags). Same random-0xc0000409-plus-assertion flake signature as previous full runs on this host (cr-1235: 14/3024; cr1249: 5/3024, different test sets). Not attributable to this PR.
  8. Hitchhiking scan clean: fbd2014 = ldd.cpp + ldd tests only; 4a6720c = date.cpp + date tests only; f6ba403 = CHANGELOG only. No format churn, no unrelated edits, CHANGELOG wording matches the code.

Nits (non-blocking)

  1. date -r/--reference is a second, still-unfolded read point in date.cpp — read_reference_time (date.cpp:1208) hands the raw operand to GetFileAttributesExW, so date -r /e/f.txt from a foreign cwd has exactly the date -f FILE 裸盘符根 /x 形态裸 ifstream 误解析——对真实存在文件报 ENOENT(cwd 盘符漂移) #1239 shape today. Correctly out of this PR's declared scope, but it is a counterexample to any "date is done" reading of the sweep — please file the follow-up ticket.
  2. ldd regression doesn't pin the verbatim operand the way the date test does (utf8_operand substring). The behavior is correct (verified: ldd: cannot open '/e/...' keeps the typed spelling); one assertion would lock it in against future message refactors.
  3. Stale baseline label: the commit body says the pre-fix oracle was installed 1.1.14; this host has 1.1.16. Immaterial to validity (the two files are identical across all three revisions — verified), but the record should say which binary actually reproduced the FAILs.

Not merging. Review worktrees (cr-1253, cr-1253-base) and the fixture were removed after the run.

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

Labels

None yet

Projects

None yet

1 participant