elfcopy: Avoid leaking dst's fd when we fail to copy a file.
We should really create the output file in the same directory as the destination file so that rename() works. This will be done in a future change as part of some work to run in capability mode. CID: 1262523 MFC after: 1 week Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
f2530c80db
commit
640ff6ed84
@ -587,15 +587,19 @@ copy_from_tempfile(const char *src, const char *dst, int infd, int *outfd,
|
||||
if ((tmpfd = open(dst, O_CREAT | O_TRUNC | O_WRONLY, 0755)) < 0)
|
||||
return (-1);
|
||||
|
||||
if (elftc_copyfile(infd, tmpfd) < 0)
|
||||
if (elftc_copyfile(infd, tmpfd) < 0) {
|
||||
(void) close(tmpfd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove the temporary file from the file system
|
||||
* namespace, and close its file descriptor.
|
||||
*/
|
||||
if (unlink(src) < 0)
|
||||
if (unlink(src) < 0) {
|
||||
(void) close(tmpfd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
(void) close(infd);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user