traceroute6: fix capabilities for the rcv socket

On the receive socket, recvmsg() and poll()/select() is called.
Therefore, CAP_EVENT is needed in addition to CAP_RECV..

While there, check the socket for readbility before calling recvmsg().

Reviewed by:		markj@
MFC after:		3 days
Sponsored by:		Netflix, Inc.
Differential Revision:	https://reviews.freebsd.org/D36878
This commit is contained in:
Michael Tuexen 2022-10-04 23:34:58 +02:00
parent b958b862b1
commit 8ff4fc03e6

View File

@ -937,7 +937,7 @@ main(int argc, char *argv[])
strerror(errno));
exit(1);
}
cap_rights_init(&rights, CAP_RECV);
cap_rights_init(&rights, CAP_RECV, CAP_EVENT);
if (caph_rights_limit(rcvsock, &rights) < 0) {
fprintf(stderr, "caph_rights_limit rcvsock: %s\n",
strerror(errno));
@ -1039,7 +1039,8 @@ wait_for_reply(int sock, struct msghdr *mhdr)
pfd[0].events = POLLIN;
pfd[0].revents = 0;
if (poll(pfd, 1, waittime * 1000) > 0)
if (poll(pfd, 1, waittime * 1000) > 0 &&
pfd[0].revents & POLLIN)
cc = recvmsg(rcvsock, mhdr, 0);
return (cc);