HomeFreeBSD

cp: Avoid closing an invalid file descriptor.

Description

cp: Avoid closing an invalid file descriptor.

  • At the end of copy(), we always close to.dir, even though it can be AT_FDCWD (in the file-to-file case) or even -1 (if we failed to open or create the destination directory). While closing an invalid file descriptor is harmless, it's still bad form.
  • In the DIR_TO_DNE case, initialize to.dir to -1 to guard against the case where mkdir() fails so we never assign anything to to.dir and end up (harmlessly, luckily) closing stdin on our way to the exit.

Coverity ID: 1609954
Fixes: 82fc0d09e862
Sponsored by: Klara, Inc.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D50391

Details

Provenance
desAuthored on May 18 2025, 7:09 PM
Reviewer
markj
Differential Revision
D50391: cp: Avoid closing an invalid file descriptor.
Parents
rG7fa19ee28c90: vm_page: reset iterator after domainset drops lock
Branches
Unknown
Tags
Unknown