Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpcap: add timeout configuration on socket connect #1091

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
rpcap: verify control socket status during reception
Signed-off-by: Kevin Boulain <[email protected]>
Signed-off-by: Gabriel Ganne <[email protected]>
  • Loading branch information
GabrielGanne committed Feb 14, 2022
commit 5b963e9c8f53561a6d932d979587f3f72d3dd788
21 changes: 20 additions & 1 deletion pcap-rpcap.c
Original file line number Diff line number Diff line change
@@ -416,7 +416,12 @@ static int pcap_read_nocb_remote(pcap_t *p, struct pcap_pkthdr *pkt_header, u_ch
/*
* 'fp->rmt_sockdata' has always to be set before calling the select(),
* since it is cleared by the select()
*
* While not strictly necessary, it's best to include the control socket.
* It allows us to check for a connection drop as the data socket may use UDP
* and as such, is without any mean to report back any error to the client.
*/
FD_SET(pr->rmt_sockctrl, &rfds);
FD_SET(pr->rmt_sockdata, &rfds);

#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
@@ -439,8 +444,22 @@ static int pcap_read_nocb_remote(pcap_t *p, struct pcap_pkthdr *pkt_header, u_ch
}
}

/*
* In the rpcap protocol, once the capture starts, the control socket isn't
* used anymore until the capture ends.
* However, it's the only way to check for connection errors
* as the data socket may uses UDP.
*/
if (FD_ISSET(pr->rmt_sockctrl, &rfds)) {
uint8 byte;
const int nread = sock_recv(pr->rmt_sockctrl, pr->ctrl_ssl, &byte, sizeof(byte),
SOCK_MSG_PEEK | SOCK_EOF_IS_ERROR, p->errbuf, PCAP_ERRBUF_SIZE);
if (nread == -1)
return -1;
}

/* There is no data waiting, so return '0' */
if (retval == 0)
if (!FD_ISSET(pr->rmt_sockdata, &rfds))
return 0;

/*