Skip to content

Commit

Permalink
Make Nsock handle all connect errors without fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Mar 20, 2017
1 parent ac8b866 commit a668a21
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Nmap Changelog ($Id$); -*-text-*-

o [Nsock] Handle any and all socket connect errors the same: raise as an Nsock
error instead of fatal. This prevents Nmap and Ncat from quitting with
"Strange error from connect:" [Daniel Miller]

o [Ncat][GH#773] Ncat in server mode properly handles TLS renegotiations and
other situations where SSL_read returns a non-fatal error. This was causing
SSL-over-TCP connections to be dropped. [Daniel Miller]
Expand Down
33 changes: 3 additions & 30 deletions nsock/src/nsock_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,39 +343,12 @@ void handle_connect_result(struct npool *ms, struct nevent *nse, enum nse_status
if (getsockopt(iod->sd, SOL_SOCKET, SO_ERROR, (char *)&optval, &optlen) != 0)
optval = socket_errno(); /* Stupid Solaris */

switch (optval) {
case 0:
if (optval == 0) {
nse->status = NSE_STATUS_SUCCESS;
break;
/* EACCES can be caused by ICMPv6 dest-unreach-admin, or when a port is
blocked by Windows Firewall (WSAEACCES). */
case EACCES:
case ECONNREFUSED:
case EHOSTUNREACH:
case ENETDOWN:
case ENETUNREACH:
case ENETRESET:
case ECONNABORTED:
case ETIMEDOUT:
case EHOSTDOWN:
case ECONNRESET:
#ifdef WIN32
case WSAEADDRINUSE:
case WSAEADDRNOTAVAIL:
#endif
#ifndef WIN32
case EPIPE: /* Has been seen after connect on Linux. */
case ENOPROTOOPT: /* Also seen on Linux, perhaps in response to protocol unreachable. */
#endif
}
else {
nse->status = NSE_STATUS_ERROR;
nse->errnum = optval;
break;

default:
/* I'd like for someone to report it */
fatal("Strange connect error from %s (%d): %s",
inet_ntop_ez(&iod->peer, iod->peerlen), optval,
socket_strerror(optval));
}

/* Now special code for the SSL case where the TCP connection was successful. */
Expand Down

0 comments on commit a668a21

Please sign in to comment.