mirror of
https://github.com/nmap/nmap.git
synced 2025-12-19 22:19:02 +00:00
Avoid crashes in Windows using poll nsock engine
WSAPoll returns WSAEINVAL when there are no valid sockets in the fdarray parameter. Individual WSAPOLLFDs can be ignored by setting them to a negative value (just as with POSIX poll(2)), but there must be at least one valid (not-ignored) socket to check. Handled this by either returning error if the error was not EINVAL, or by checking each WSAPOLLFD in the fdarray; at the first valid one, return the error, since this was not the reason for the error. If none are valid, continue, ignoring the error.
This commit is contained in:
@@ -356,9 +356,17 @@ int poll_loop(struct npool *nsp, int msec_timeout) {
|
||||
} while (results_left == -1 && sock_err == EINTR); /* repeat only if signal occurred */
|
||||
|
||||
if (results_left == -1 && sock_err != EINTR) {
|
||||
nsock_log_error("nsock_loop error %d: %s", sock_err, socket_strerror(sock_err));
|
||||
nsp->errnum = sock_err;
|
||||
return -1;
|
||||
#ifdef WIN32
|
||||
for (int i = 0; sock_err != EINVAL || i <= pinfo->max_fd; i++) {
|
||||
if (sock_err != EINVAL || pinfo->events[i].fd != -1) {
|
||||
#endif
|
||||
nsock_log_error("nsock_loop error %d: %s", sock_err, socket_strerror(sock_err));
|
||||
nsp->errnum = sock_err;
|
||||
return -1;
|
||||
#ifdef WIN32
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
iterate_through_event_lists(nsp);
|
||||
|
||||
Reference in New Issue
Block a user