mirror of
https://github.com/uutils/coreutils.git
synced 2026-05-06 07:26:38 -04:00
bd170a5d4b
When `cp -p` cannot chown the destination to the source's owner (e.g. a non-root user copying a root-owned setuid file), GNU cp strips the setuid and setgid bits from the applied mode so the destination does not give the copying user elevated privileges via the copy. uutils was unconditionally applying the source mode, producing user-owned files with a live setuid bit. Track `ownership_preserved` alongside the existing chown retry logic and, in the subsequent `handle_preserve(mode, ...)` block, mask off `0o6000` from the source's mode when ownership could not be preserved. The sticky bit (01000) is kept, matching GNU.