Check the return value of fcntl() when setting FD_CLOEXEC.

This should never fail unless the fd is invalid.
Problem reported by Matthias Gerstner of SUSE.
This commit is contained in:
Todd C. Miller
2021-01-06 10:16:00 -07:00
parent b132def0b1
commit 71339c574f
5 changed files with 56 additions and 20 deletions

View File

@@ -56,8 +56,10 @@ linux_audit_open(void)
au_fd = AUDIT_NOT_CONFIGURED;
else
sudo_warn("%s", U_("unable to open audit system"));
} else {
(void)fcntl(au_fd, F_SETFD, FD_CLOEXEC);
} else if (fcntl(au_fd, F_SETFD, FD_CLOEXEC) == -1) {
sudo_warn("%s", U_("unable to open audit system"));
audit_close(au_fd);
au_fd = -1;
}
debug_return_int(au_fd);
}