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

This commit is contained in:
Michal Hlavinka 2012-08-13 12:21:44 +02:00
parent 1ce49799c3
commit beb89254d6
2 changed files with 42 additions and 1 deletions

34
ncat_reg_stdin.diff Normal file
View File

@ -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.");

View File

@ -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@redhat.com> - 2:6.01-5
- ncat did not work when file was used as input (#845005)
* Tue Jul 24 2012 Michal Hlavinka <mhlavink@redhat.com> - 2:6.01-4
- add nc wrapper with socat as a fallback for unix sockets