Avoid clobbering nsiod.peer with junk data if recvfrom doesn't set src_addr

This commit is contained in:
dmiller 2016-05-13 02:13:25 +00:00
parent 50e9080ef1
commit f38b959593
2 changed files with 9 additions and 1 deletions

View file

@ -644,7 +644,11 @@ static int do_actual_read(struct npool *ms, struct nevent *nse) {
err = socket_errno();
break;
}
if (peerlen > 0) {
/* Windows will ignore src_addr and addrlen arguments to recvfrom on TCP
* sockets, so peerlen is still sizeof(peer) and peer is junk. Instead,
* only set this if it's not already set.
*/
if (peerlen > 0 && iod->peerlen == 0) {
assert(peerlen <= sizeof(iod->peer));
memcpy(&iod->peer, &peer, peerlen);
iod->peerlen = peerlen;