Skip to content

Commit 525c048

Browse files
committed
fix: only chown when both UID and GID are set (archive mode)
1 parent 2e4786f commit 525c048

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/system/guest_agent/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,9 @@ func (s *guestServer) CopyToGuest(stream pb.GuestService_CopyToGuestServer) erro
424424
}
425425

426426
// Set ownership if provided (archive mode)
427-
if start.Uid > 0 || start.Gid > 0 {
427+
// Only chown when both UID and GID are explicitly set (non-zero)
428+
// to avoid accidentally setting one to root (0) when only the other is specified
429+
if start.Uid > 0 && start.Gid > 0 {
428430
if err := os.Chown(start.Path, int(start.Uid), int(start.Gid)); err != nil {
429431
log.Printf("[guest-agent] warning: failed to set ownership on %s: %v", start.Path, err)
430432
}

0 commit comments

Comments
 (0)