Repository navigation
fix(shred): fold POSIX drive-dialect operands before any overwrite (#1240) - #1250
Conversation
…1240) shred handed the raw operand ('/e/f', '/cygdrive/e/f', '/mnt/e/f') to CreateFileW, and Win32 resolves a leading '/e' against the CURRENT drive. For the toolset's data-destroying command that misparse was doubly dangerous (#1230 sweep): from a C: cwd with a shadow 'C:\e\f' present, 'shred /e/f' silently overwrote the SHADOW and exited 0 - probe-verified before the fix (shadow destroyed, requested E:\ file untouched) - and with no shadow it reported 'cannot open' for a perfectly good E:\ file. Both the wrong-target overwrite and the false success/failure pair are gone: every operand folds once through the shared make_api_path_operand boundary before the overwrite, the --force retry, the native-glob pass and the -u/--remove unlink, and the Win32 calls take the extended form like the other post-#1233 commands. Messages keep printing the operand spelling as typed (glob matches print the matched path), so a missing operand still fails with rc 1 quoting what the user typed, like MSYS. Regressions synthesize the dialect spelling from the TempDir's own drive (zero-pass parse-layer landing, one destructive overwrite proof, cygdrive/mnt spellings, cwd-on-other-drive shadow negative, bare-drive-root no-creation, Windows-form idempotence, missing-operand typed-spelling pin, wildcard-dialect glob landing, -u removal) and pass on any host.
Independent code review — verdict: APPROVE (no blockers; non-blocking notes only)Reviewed independently from a fresh detached worktree at 4656417 (the branch is checked out in the implementation tree, so the review tree was detached at the same commit; merge-base with origin/main = 6e8ea19, the commit that includes #1245 — single commit, exactly as described). Baseline binary rebuilt from pristine 6e8ea19 in a second detached tree. All probes via Verified (all re-executed)
Nits (non-blocking)
Cleanup witnessed: probe trees |
# Conflicts: # CHANGELOG.md
Ticket
#1240 - shred (secure erase) bare-drive-letter dialect misparse. Audited as the highest data-safety risk of the dialect sweep: shred is an overwrite-destroy command, so a dialect misparse here is either a wrong-target destruction or a false success. Both faces were probe-verified before the fix and both are closed.
The bug
shredhanded the raw operand toCreateFileW. Win32 resolves a leading/eagainst the current drive, so from aC:cwdshred /e/Data/secret:C:\e\probe-wc\victim.txtpresent, the tool overwrote THAT shadow file with random bytes and exited 0 - the requestedE:victim was left completely intact (marker unchanged);cannot open '/e/probe-wc/victim.txt'(rc 1) for a perfectly goodE:file./cygdrive/e/...and/mnt/e/...spellings misresolved identically.The fix
Follows the #1233/#1234/#1245 boundary precedent exactly:
native_path::make_api_path_operandbefore the overwrite, the--forceread-only retry, the native-glob pass (a/e/*.logpattern now expands against the operand drive, not the cwd drive) and the-u/--removeunlink;operand.extended(long-path safe, like chattr/cp post-mkdir 裸盘符根 /x 形态在 cwd 盘创建/误报——创建主路径未过盘符折叠(mkdir -p 会真建影子目录) #1233);-(stdout wipe) handling is untouched;/dev/null-class operands now resolve through the standard pseudo-device boundary like sibling commands.Probe evidence
PS/cmd native argv throughout; self-created probe files only;
-n 0= zero overwrite passes (content-preserving parse-layer proof). Shadow witnessesC:\e,C:\d,D:\everified absent before, between and after every probe.Baseline (pristine origin/main), cwd
C:\Users\cmx:/e/probe-wc/victim.txtC:\e\...(file exists on E:)/cygdrive/e/...,/mnt/e/...E:\probe-wc\victim.txt-n 1, shadow planted)C:\e\...destroyed, E: victim untouchedFixed (this PR), 5 spellings x 2 cwds:
/e/probe-wc/victim.txt-n 0)/cygdrive/e/probe-wc/victim.txt/mnt/e/probe-wc/victim.txtE:\probe-wc\victim.txt(Windows form)E:/probe-wc/victim.txt(forward-slash form)/e/...absent-1240.txt(error path)Plus, on the fixed binary:
-n 1overwrite lands on the E: file (marker replaced) while a planted shadow stayed untouched (exact inverse of the baseline smoking gun); a native-glob dialect pattern (/e/probe-wc/victim*.txt,WINUX_SHELL_GLOB=native) resolves on the operand drive;-uremoves the E: file.Oracle cross-check (MSYS shred, Git for Windows
/usr/bin/shred): missing operand gives rc 1 under every spelling from both cwds - rc parity holds. Oracle messages quote the user-referenced path (MSYS prints either the raw spelling or its Windows fold depending on the invoking parent - never a shadow path); ours always quotes the typed spelling per the #1234 house rule.Tests
8 new regressions in
tests/unit/shred/shred_unit_test.cpp(dialect spelling synthesized from the TempDir's own drive, so they pass on any host; parse-layer-n 0assertions plus one destructive overwrite proof on a test-created file):exists()negative (the "shadow path is never shred" witness - parse-layer, not a real erase)/efails without creating<drive>:\e-udialect removalshredsubset: 18/18 green. Fullctest: 3013/3013 (second run exit 0; the first run had 9 unrelated 0xc0000409 load flakes that all pass in isolation and in the second run). Build viascripts/build.py; changed files clang-format clean.Notes