Repository navigation
WIP: E-face audit fixes — join_tail clamp, rm link classification, cp error accounting + self-copy identity, install -b backup gate (#1432-#1436) - #1437
Merged
Conversation
caomengxuan666
force-pushed
the
fix/winx-e-face
branch
from
October 29, 2026 00:02
e6cdb7e to
c0ce487
Compare
join_tail seeded its component stack with the native base itself, so a
".." in the shell tail popped base components: with root D:\pkg\root the
spelling "/../x" resolved to D:\pkg\x and "/../../../Windows/System32"
left the payload root entirely. rubash's map_logical_path — the fold the
header comment claims to mirror — collects the operand's components into
an empty stack (".." at the root is a no-op, the POSIX root clamp) and
only then joins under the root, so the shell and its coreutils children
resolved the same spelling to different files (audit E-2, re-verified
on current main).
Fold the tail against an empty stack and append only the surviving
components to the base. The root mount now matches rubash exactly;
sub-mounts (/tmp, /var/tmp, /home, /mnt/X) clamp at their own base
instead of escaping into unmounted native space.
Regression pins (tests/unit/cat/cat_unit_test.cpp):
- issue1432_shell_root_dotdot_clamps_at_root: "/../x" and "/../../x"
read the file inside the root, not the same-named sibling outside it;
"/sub/../x" still folds lexically below the base
- issue1432_tmp_mount_dotdot_clamps_at_base: same clamp at the /tmp
mount
remove_path classified operands by operand_target_attributes_w, which reports the TARGET's attributes for a link. A symlink (or junction) to a directory therefore hit the plain-directory branch: "rm linkdir" refused with "Is a directory" without -r, and "rm -r linkdir" descended through the link and deleted the target's contents (audit E-3). A dangling link read as INVALID_FILE_ATTRIBUTES and was reported missing. Probe the link itself once (operand_link_attributes, the FindFirstFileW probe the -i prompt selection already used, #1327) and treat a link operand as a leaf, per GNU's lstat rule: unlink the link only, choosing DeleteFileW/RemoveDirectoryW by the link's own DIRECTORY bit — the same split the recursion already applies to link children. A trailing separator opts out (it dereferences; the directory branches then apply to the target, as for "rm linkdir/"). The prompt face is unchanged. Regression pins (tests/unit/rm/rm_unit_test.cpp): - issue1433_rm_directory_symlink_removes_link_only: plain and -r forms unlink the link; the target's contents survive both - issue1433_rm_directory_junction_removes_link_only: same for a junction (no privilege needed to create) - issue1433_rm_dangling_symlink_removes_link: a dangling link unlinks instead of reporting "No such file or directory" - issue1433_rm_real_directory_still_refused_without_r: control — a real directory without -r is still "Is a directory"
…1434) The plain copy did `dest << src.rdbuf()`, checked only dest.bad(), and never looked at the flush/close results: a source read failure mid-copy (media error, concurrent truncation) stops the streambuf insertion silently — it surfaces at that layer as EOF and sets no state on src — and a buffered write failure landing at close (the classic ENOSPC point) was discarded the same way. A truncated copy exited 0 (audit E-4). The sparse path already checks every Win32 call; the stream path now accounts for all three of its segments: - read: reconcile the inserted byte count against the source size captured before copying (only a short copy is an error; growth during the copy and non-seekable sources are exempt) - write: the existing dest.bad() check stays - flush/close: both states are checked and reported as write errors Diagnostics reuse the in-file forms ("error reading '<src>'" / "error writing '<dest>'"). Regression pins (tests/unit/cp/cp_unit_test.cpp): - issue1434_stream_copy_completes_at_eof_sizes: the reconciliation never misfires on a complete copy — empty, one-byte and 3 MiB files copy byte-exact with exit 0 (dynamic fault injection for the read and flush arms needs a full-disk ramdisk, as audit E-4 recorded)
…1435) copy_directory_helper's guard was a raw prefix test on the operand strings (destPath.find(srcPath) == 0). Equivalent spellings of "inside the source" — "./a", the case variant "A" on a case-insensitive volume, an absolute or drive form — walked straight past it; the copy then enumerated its own freshly created destination and self-nested to the depth cap of 100, leaving a deep garbage tree (audit E-5). The file level already compared identity (std::filesystem::equivalent); the directory level now does the equivalent: - directory_identity_key folds each operand through the shared API-path boundary (the form the opens will use), makes it absolute and lexically normal, and folds ASCII case - directory_key_contains tests equality/containment on a component boundary The check fires before the destination directory is created, so a rejected copy leaves nothing behind. The existing GNU-form diagnostic is unchanged. A destination reached through a link into the source is still bounded by the (dev,ino) ancestor-cycle guard, as before. Regression pins (tests/unit/cp/cp_unit_test.cpp): - issue1435_self_copy_equivalent_spellings_rejected: "./a", "A" and an absolute forward-slash destination are all refused with the "into itself" diagnostic and create no nesting - issue1435_sibling_copy_still_works: control — a normal recursive copy to a sibling is unaffected
The backup block used MoveFileExW's result only to decide whether to print the verbose "(backup: ...)" line. When the rename failed — the backup name occupied, a permission error — the install proceeded to CopyFileW over DEST anyway: the user had explicitly asked for a backup, the original was destroyed without one, and the exit code was 0 (audit E-7). A failed backup rename now diagnoses "install: cannot backup '<dest>': <error>" (the file's existing error-text helper, and GNU's wording), marks the pair failed and skips it, leaving DEST untouched — the same treatment #1357 already gives source-validation failures in this loop. Regression pins (tests/unit/install/install_unit_test.cpp): - issue1436_install_backup_failure_aborts_overwrite: a non-empty directory occupying "dest~" makes the rename fail; exit is nonzero, the diagnostic names the backup failure, DEST keeps its content - issue1436_install_backup_success_still_installs: control — an unblocked -b backs up and installs exactly as before
caomengxuan666
force-pushed
the
fix/winx-e-face
branch
from
October 29, 2026 00:32
c0ce487 to
6d892ae
Compare
Member
Author
|
CI adjudication (main-session gate record): round 1 red was this branch's own cat-pin compile error (fixed, folded into the #1432 commit). Round 2 built fully and failed exactly 3 ctest cases — all empty-source copies broken by the #1434 first design (the streambuf inserter's zero-character failbit quirk, which also poisons tellp); root-caused and redesigned as an explicit sgetn counting loop inside the #1434 commit. Round 3 on head 6d892ae: CMake Windows Multi-Arch CI success on x64 (build + full ctest) and arm64, GNU master differential success; all 11 new pins verified Passed by name in the run log. Full ledger: cluster REPORT §6. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP: WinuxCmd E-face audit fixes — five commits, one per issue. Each fix was re-derived at its code site on current main (58613c2) against the audit's findings (rc-150 audit, E face) and the GNU coreutils 9.4 oracle; each commit carries its own regression pins in the per-command unit tests.
Fixes #1432
Fixes #1433
Fixes #1434
Fixes #1435
Fixes #1436
Per-issue summary
join_tailclamped at the mount base. The tail fold now runs against an empty component stack (exactly rubashmap_logical_path's fold) and only surviving components are appended to the base:/../xcan no longer escape the payload root or a sub-mount base into unmounted native space. Pins:issue1432_shell_root_dotdot_clamps_at_root,issue1432_tmp_mount_dotdot_clamps_at_base(cat suite — the shared boundary exercised end to end).operand_link_attributes(the FindFirstFileW probe from [rm] -i prompts diverge: generic 'remove?' wording for files/dirs, and prompts before reporting a missing operand #1327) now drives classification: a link operand is a leaf —rm linkdirunlinks it without-r,rm -r linkdirnever descends into the target, a dangling link unlinks instead of reporting ENOENT. Trailing separator still dereferences. The root-segment (E-1) shapes were NOT exercised — pins use temp-dir symlink/junction shapes only. Pins:issue1433_rm_directory_symlink_removes_link_only,issue1433_rm_directory_junction_removes_link_only,issue1433_rm_dangling_symlink_removes_link,issue1433_rm_real_directory_still_refused_without_r(control).error reading);dest.flush()anddest.close()states are now checked (buffered ENOSPC lands at close). The sparse path already checked every Win32 call. Pin:issue1434_stream_copy_completes_at_eof_sizes(the reconciliation never misfires on complete copies — 0 B / 1 B / 3 MiB; dynamic fault injection for the read/flush arms needs a full-disk ramdisk, as audit E-4 recorded)../a,A, and absolute/drive spellings are now refused with the existing "into itself" diagnostic and leave no garbage tree. Pins:issue1435_self_copy_equivalent_spellings_rejected,issue1435_sibling_copy_still_works(control).MoveFileExWnow diagnosesinstall: cannot backup '<dest>': <error>, marks the pair failed and skips it with DEST untouched, instead of silently overwriting without a backup at exit 0. Pins:issue1436_install_backup_failure_aborts_overwrite(non-empty directory occupyingdest~),issue1436_install_backup_success_still_installs(control).Notes
scripts/i18n_batch.py extractrun on pristine main and on this branch produces byte-identical catalogs (3621 messages) — no new catalog keys, so no winuxcmd-i18n companion change is needed for this batch.