Use WSARecv instead of WSARecvFrom when the from field is empty

Windows will throw WSAEFAULT if WSARecvFrom is called with a NULL lpFrom and/or fromlen

Close #17163
This commit is contained in:
Denis Charmet 2016-09-07 19:08:35 +02:00
parent 0716db4d95
commit 0ca74870c4
1 changed files with 6 additions and 1 deletions

View File

@ -54,8 +54,13 @@ ssize_t recvmsg(int fd, struct msghdr *msg, int flags)
DWORD dwFlags = flags;
INT fromlen = msg->msg_namelen;
DWORD rcvd;
int ret = WSARecvFrom(fd, buf, msg->msg_iovlen, &rcvd, &dwFlags,
int ret;
if (fromlen)
ret = WSARecvFrom(fd, buf, msg->msg_iovlen, &rcvd, &dwFlags,
msg->msg_name, &fromlen, NULL, NULL);
else
ret = WSARecv(fd, buf, msg->msg_iovlen, &rcvd, &dwFlags,
NULL, NULL);
free(buf);
if (ret == 0)