epoll: epoll_wait() should check whether maxevents is valid

This commit is contained in:
Bert Belder 2017-09-25 19:09:51 +02:00
parent 6629ae68b5
commit e4f213007f

View File

@ -152,6 +152,14 @@ static int _ep_wait(ep_port_t* port_info,
ULONGLONG due = 0;
DWORD gqcs_timeout;
/* Check whether `maxevents` is in range. */
if (maxevents <= 0)
return_error(-1, ERROR_INVALID_PARAMETER);
/* Compute how much overlapped entries can be dequeued at most. */
if ((size_t) maxevents > _EPOLL_MAX_COMPLETION_COUNT)
maxevents = _EPOLL_MAX_COMPLETION_COUNT;
/* Compute the timeout for GetQueuedCompletionStatus, and the wait end
* time, if the user specified a timeout other than zero or infinite.
*/
@ -164,10 +172,6 @@ static int _ep_wait(ep_port_t* port_info,
gqcs_timeout = INFINITE;
}
/* Compute how much overlapped entries can be dequeued at most. */
if ((size_t) maxevents > _EPOLL_MAX_COMPLETION_COUNT)
maxevents = _EPOLL_MAX_COMPLETION_COUNT;
/* Dequeue completion packets until either at least one interesting event
* has been discovered, or the timeout is reached.
*/