mirror of
https://github.com/nmap/nmap.git
synced 2026-01-01 04:19:02 +00:00
Automatically enforce the use of the nsock select engine if we detect that stdin
is a regular file. Under linux, that provides epoll(7), this allows proper behavior when redirecting a regular file to stdin (e.g.: 'ncat localhost < file.txt'). Bug was reported by Michal Hlavinka. See http://seclists.org/nmap-dev/2012/q3/490 for more details.
This commit is contained in:
@@ -458,11 +458,31 @@ bail:
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(LINUX)
|
||||
static int stdin_is_reg(void) {
|
||||
struct stat buf;
|
||||
|
||||
if (fstat(STDIN_FILENO, &buf) < 0)
|
||||
fatal("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");
|
||||
#endif
|
||||
|
||||
/* Create an nsock pool */
|
||||
if ((mypool = nsp_new(NULL)) == NULL)
|
||||
bye("Failed to create nsock_pool.");
|
||||
|
||||
Reference in New Issue
Block a user