[nmap] ncat did not work when file was used as input (#845005)

Michal Hlavinka mhlavink at fedoraproject.org
Mon Aug 13 10:21:55 UTC 2012


commit beb89254d684920c0cfae6edc85bd27540bbeb3c
Author: Michal Hlavinka <mhlavink at redhat.com>
Date:   Mon Aug 13 12:21:44 2012 +0200

    ncat did not work when file was used as input (#845005)

 ncat_reg_stdin.diff |   34 ++++++++++++++++++++++++++++++++++
 nmap.spec           |    9 ++++++++-
 2 files changed, 42 insertions(+), 1 deletions(-)
---
diff --git a/ncat_reg_stdin.diff b/ncat_reg_stdin.diff
new file mode 100644
index 0000000..8f0632e
--- /dev/null
+++ b/ncat_reg_stdin.diff
@@ -0,0 +1,34 @@
+diff -up nmap-6.01/ncat/ncat_connect.c.ncat_reg_stdin nmap-6.01/ncat/ncat_connect.c
+--- nmap-6.01/ncat/ncat_connect.c.ncat_reg_stdin	2012-03-01 07:53:35.000000000 +0100
++++ nmap-6.01/ncat/ncat_connect.c	2012-08-08 18:34:36.971502138 +0200
+@@ -458,10 +458,30 @@ 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.");
diff --git a/nmap.spec b/nmap.spec
index ec5c268..ccc67eb 100644
--- a/nmap.spec
+++ b/nmap.spec
@@ -4,7 +4,7 @@ Name: nmap
 Epoch: 2
 Version: 6.01
 #global prerelease TEST5
-Release: 4%{?dist}
+Release: 5%{?dist}
 # nmap is GPLv2
 # zenmap is GPLv2 and LGPLv2+ (zenmap/higwidgets) and GPLv2+ (zenmap/radialnet)
 # libdnet-stripped is BSD (advertising clause rescinded by the Univ. of California in 1999) with some parts as Public Domain (crc32)
@@ -32,6 +32,9 @@ Patch2: nmap-4.52-noms.patch
 # rhbz#637403, workaround for rhbz#621887=gnome#623965
 Patch4: zenmap-621887-workaround.patch
 
+# upstream provided patch for rhbz#845005, not yet in upstream repository
+Patch5: ncat_reg_stdin.diff
+
 URL: http://nmap.org/
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 BuildRequires: openssl-devel, gtk2-devel, lua-devel, libpcap-devel, pcre-devel
@@ -81,6 +84,7 @@ uses.
 %patch1 -p1 -b .mktemp
 %patch2 -p1 -b .noms
 %patch4 -p1 -b .bz637403
+%patch5 -p1 -b .ncat_reg_stdin
 
 #be sure we're not using tarballed copies of some libraries
 rm -rf liblua libpcap libpcre macosx mswin32
@@ -208,6 +212,9 @@ rm -rf $RPM_BUILD_ROOT
 %{_mandir}/man1/xnmap.1.gz
 
 %changelog
+* Mon Aug 13 2012 Michal Hlavinka <mhlavink at redhat.com> - 2:6.01-5
+- ncat did not work when file was used as input (#845005)
+
 * Tue Jul 24 2012 Michal Hlavinka <mhlavink at redhat.com> - 2:6.01-4
 - add nc wrapper with socat as a fallback for unix sockets
 


More information about the scm-commits mailing list