1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-20 13:19:01 +00:00

shutdown write socket on stdin EOF in listen mode.

http://seclists.org/nmap-dev/2012/q4/337
This commit is contained in:
david
2012-11-29 03:51:06 +00:00
parent 2bfeace798
commit 297e0a1dfd
3 changed files with 43 additions and 6 deletions

View File

@@ -1,5 +1,9 @@
# Nmap Changelog ($Id$); -*-text-*-
o [Ncat] Shut down the write part of connected sockets in listen mode
when stdin hits EOF, just as was already done in connect mode.
[Michal Hlavinka]
o [Zenmap] Removed a crashing error that could happen when canceling a
"Print to File" on Windows:
Traceback (most recent call last):

View File

@@ -322,10 +322,14 @@ static int ncat_listen_stream(int proto)
} else {
/* Read from stdin and write to all clients. */
rc = read_stdin();
if (rc == 0 && o.sendonly)
/* There will be nothing more to send. If we're not
receiving anything, we can quit here. */
return 0;
if (rc == 0) {
if (o.sendonly) {
/* There will be nothing more to send. If we're not
receiving anything, we can quit here. */
return 0;
}
shutdown_sockets(SHUT_WR);
}
if (rc < 0)
return 1;
}
@@ -513,6 +517,20 @@ int read_stdin(void)
return nbytes;
}
void shutdown_sockets(int how)
{
struct fdinfo *fdn;
int i;
for (i = 0; i <= broadcast_fdlist.fdmax; i++) {
if (!FD_ISSET(i, &master_broadcastfds))
continue;
fdn = get_fdinfo(&broadcast_fdlist, i);
shutdown(fdn->fd, how);
}
}
/* Read from a client socket and write to stdout. Return the number of bytes
read from the socket, or -1 on error. */
int read_socket(int recv_fd)

View File

@@ -742,7 +742,7 @@ server_client_test_tcp_sctp_ssl "Server sends EOF after client disconnect",
};
kill_children;
server_client_test "Shutdown() connection when reading EOF",
server_client_test "Client shutdown()s connection when reading EOF",
[], [], sub {
my $resp;
@@ -753,7 +753,22 @@ server_client_test "Shutdown() connection when reading EOF",
close($c_in);
$resp = timeout_read($s_out);
!defined($resp) or die "Server didn't send EOF (got \"$resp\")";
!defined($resp) or die "Server didn't get EOF (got \"$resp\")";
};
kill_children;
server_client_test "Server shutdown()s connection when reading EOF",
[], [], sub {
my $resp;
syswrite($s_in, "abc\n");
$resp = timeout_read($c_out) or die "Read timeout";
$resp eq "abc\n" or die "Client got \"$resp\", not \"abc\\n\"";
close($s_in);
$resp = timeout_read($c_out);
!defined($resp) or die "Client didn't get EOF (got \"$resp\")";
};
kill_children;