mirror of
https://github.com/nmap/nmap.git
synced 2025-12-29 10:59:02 +00:00
Avoid selecting on STDIN on Windows. Fixes #978
This commit is contained in:
@@ -428,6 +428,8 @@ int fselect(int s, fd_set *rmaster, fd_set *wmaster, fd_set *emaster, struct tim
|
||||
int iter = -1, i;
|
||||
struct timeval stv;
|
||||
fd_set rset, wset, eset;
|
||||
int r_stdin = rmaster != NULL && FD_ISSET(STDIN_FILENO, rmaster);
|
||||
int e_stdin = emaster != NULL && FD_ISSET(STDIN_FILENO, emaster);
|
||||
|
||||
/* Figure out whether there are any FDs in the sets, as @$@!$# Windows
|
||||
returns WSAINVAL (10022) if you call a select() with no FDs, even though
|
||||
@@ -441,8 +443,8 @@ int fselect(int s, fd_set *rmaster, fd_set *wmaster, fd_set *emaster, struct tim
|
||||
s--;
|
||||
}
|
||||
|
||||
/* Handle the case where stdin is not being read from. */
|
||||
if (rmaster == NULL || !FD_ISSET(STDIN_FILENO, rmaster)) {
|
||||
/* Handle the case where stdin is not in scope. */
|
||||
if (!(r_stdin || e_stdin)) {
|
||||
if (s > 0) {
|
||||
/* Do a normal select. */
|
||||
return select(s, rmaster, wmaster, emaster, tv);
|
||||
@@ -476,7 +478,10 @@ int fselect(int s, fd_set *rmaster, fd_set *wmaster, fd_set *emaster, struct tim
|
||||
stdin_thread_started = 1;
|
||||
}
|
||||
|
||||
FD_CLR(STDIN_FILENO, rmaster);
|
||||
if (r_stdin)
|
||||
FD_CLR(STDIN_FILENO, rmaster);
|
||||
if (e_stdin)
|
||||
FD_CLR(STDIN_FILENO, emaster);
|
||||
|
||||
if (tv) {
|
||||
int usecs = (tv->tv_sec * 1000000) + tv->tv_usec;
|
||||
@@ -509,7 +514,7 @@ int fselect(int s, fd_set *rmaster, fd_set *wmaster, fd_set *emaster, struct tim
|
||||
else
|
||||
usleep(stv.tv_sec * 1000000UL + stv.tv_usec);
|
||||
|
||||
if (fds_ready > -1 && win_stdin_ready()) {
|
||||
if (fds_ready > -1 && r_stdin && win_stdin_ready()) {
|
||||
FD_SET(STDIN_FILENO, &rset);
|
||||
fds_ready++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user