[nmap/f17] shutdown socket on EOF (#845075)

Michal Hlavinka mhlavink at fedoraproject.org
Wed Sep 19 15:02:19 UTC 2012


commit b9604dbd97727688e193fb14a8277aa24807af4a
Author: Michal Hlavinka <mhlavink at redhat.com>
Date:   Wed Sep 19 17:02:15 2012 +0200

    shutdown socket on EOF (#845075)
    
    - ncat did not work when file was used as input (#845005)

 ncat_reg_stdin.diff    |   34 ++++++++++++++++++++++++++++++++++
 nmap-6.01-r29743.patch |   27 +++++++++++++++++++++++++++
 nmap.spec              |   14 +++++++++++++-
 3 files changed, 74 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-6.01-r29743.patch b/nmap-6.01-r29743.patch
new file mode 100644
index 0000000..58c44c0
--- /dev/null
+++ b/nmap-6.01-r29743.patch
@@ -0,0 +1,27 @@
+diff -up nmap-6.01/ncat/ncat_connect.c.r29743 nmap-6.01/ncat/ncat_connect.c
+--- nmap-6.01/ncat/ncat_connect.c.r29743	2012-09-19 14:56:37.889102887 +0200
++++ nmap-6.01/ncat/ncat_connect.c	2012-09-19 14:56:56.148241822 +0200
+@@ -113,6 +113,14 @@
+ #include <openssl/err.h>
+ #endif
+ 
++#ifdef WIN32
++/* Define missing constant for shutdown(2).
++ * See:
++ * http://msdn.microsoft.com/en-us/library/windows/desktop/ms740481%28v=vs.85%29.aspx
++ */
++#define SHUT_WR SD_SEND
++#endif
++
+ struct conn_state {
+     nsock_iod sock_nsi;
+     nsock_iod stdin_nsi;
+@@ -732,6 +740,8 @@ static void read_stdin_handler(nsock_poo
+         if (o.sendonly) {
+             /* In --send-only mode, exit after EOF on stdin. */
+             nsock_loop_quit(nsp);
++        } else {
++          shutdown(nsi_getsd(cs.sock_nsi), SHUT_WR);
+         }
+         return;
+     } else if (status == NSE_STATUS_ERROR) {
diff --git a/nmap.spec b/nmap.spec
index e905798..628193a 100644
--- a/nmap.spec
+++ b/nmap.spec
@@ -3,7 +3,7 @@ Summary: Network exploration tool and security scanner
 Name: nmap
 Version: 6.01
 #global prerelease TEST5
-Release: 1%{?dist}
+Release: 2%{?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)
@@ -25,6 +25,12 @@ 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
+
+# shutdown socket on EOF, sent upstream
+Patch6: nmap-6.01-r29743.patch
+
 URL: http://nmap.org/
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 Epoch: 2
@@ -60,6 +66,8 @@ be installed before installing nmap front end.
 %patch1 -p1 -b .mktemp
 %patch2 -p1 -b .noms
 %patch4 -p1 -b .bz637403
+%patch5 -p1 -b .ncat_reg_stdin
+%patch6 -p1 -b .r29743
 
 #be sure we're not using tarballed copies of some libraries
 rm -rf liblua libpcap libpcre macosx mswin32
@@ -176,6 +184,10 @@ rm -rf $RPM_BUILD_ROOT
 %{_mandir}/man1/xnmap.1.gz
 
 %changelog
+* Wed Sep 19 2012 Michal Hlavinka <mhlavink at redhat.com> - 2:6.01-2
+- shutdown socket on EOF (#845075)
+- ncat did not work when file was used as input (#845005)
+
 * Mon Jun 18 2012 Michal Hlavinka <mhlavink at redhat.com> - 2:6.01-1
 - nmap updated to 6.01
 


More information about the scm-commits mailing list