Use the fallback nsock engine by default in order to maximize

compatibility between systems and use cases. [Henri Doreau]

There were known issues with the following cases:
  * epoll and regular files
  * kqueue and regular files
  * WSAPoll and stdin

The --nsock-engine=<ENGINE> can still be used to bypass this
default choice.

See: http://seclists.org/nmap-dev/2012/q4/173
This commit is contained in:
henri 2012-11-13 08:40:49 +00:00
parent 64f874d835
commit 9d7c017cf7
5 changed files with 12 additions and 25 deletions

View file

@ -1,5 +1,8 @@
# Nmap Changelog ($Id$); -*-text-*-
o [Ncat] Use the fallback nsock engine by default in order to maximize
compatibility between systems and use cases. [Henri Doreau]
o [Ncat] Added support for Unix domain sockets. The new -U and
--unixsock options activate this mode. [Tomas Hozza]

View file

@ -477,37 +477,17 @@ bail:
return -1;
}
#if defined(LINUX)
static int stdin_is_reg(void) {
struct stat buf;
if (fstat(STDIN_FILENO, &buf) < 0)
bye("fstat(): %s", strerror(errno));
return S_ISREG(buf.st_mode);
}
#endif
int ncat_connect(void)
{
nsock_pool mypool;
int rc;
#if defined(LINUX)
/* -- Hack!!
* epoll(7) doesn't support regular files (e.g.: ncat < file.c)
* If we detect that STDIN is a regular file, then we enforce
* the use of the select-based engine. */
if (stdin_is_reg())
nsock_set_default_engine("select");
#elif defined(WIN32)
/* -- Hack!!
* Unconditionally use the select engine on windows.
* The poll engine (WSAPoll) is currently unable to handle
* read events on stdin.
/* Unless explicitely asked not to do so, ncat uses the
* fallback nsock engine to maximize compatibility between
* operating systems and the different use cases.
*/
nsock_set_default_engine("select");
#endif
if (!o.nsock_engine)
nsock_set_default_engine("select");
/* Create an nsock pool */
if ((mypool = nsp_new(NULL)) == NULL)

View file

@ -160,6 +160,8 @@ void options_init(void)
addrset_init(&o.denyset);
o.httpserver = 0;
o.nsock_engine = 0;
o.numsrcrtes = 0;
o.srcrteptr = 4;

View file

@ -142,6 +142,7 @@ struct options {
struct addrset allowset;
struct addrset denyset;
int httpserver;
int nsock_engine;
/* Loose source-routing stuff */
struct in_addr srcrtes[8];

View file

@ -424,6 +424,7 @@ int main(int argc, char *argv[])
} else if (strcmp(long_options[option_index].name, "nsock-engine") == 0) {
if (nsock_set_default_engine(optarg) < 0)
bye("Unknown or non-available engine: %s.", optarg);
o.nsock_engine = 1;
} else if (strcmp(long_options[option_index].name, "broker") == 0) {
o.broker = 1;
/* --broker implies --listen. */