diff --git a/CHANGELOG b/CHANGELOG index 18120d744..a91282e03 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,10 @@ #s wa Nmap Changelog ($Id$); -*-text-*- +o [GH#978] Fixed Nsock on Windows giving errors when selecting on STDIN. This + was causing Ncat 7.60 in connect mode to quit with error: + libnsock select_loop(): nsock_loop error 10038: An operation was attempted on something that is not a socket. + [nnposter] + o [NSE][GH#958] Two new libraries for NSE. - punycode - idna diff --git a/nbase/nbase_misc.c b/nbase/nbase_misc.c index a999e55cd..9851cc860 100644 --- a/nbase/nbase_misc.c +++ b/nbase/nbase_misc.c @@ -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++; }