From db84088f4e334a41a193a16d1743db3443729621 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Mon, 5 Oct 2026 20:47:09 -0400 Subject: [PATCH] Fix Ncat receive-only listeners exiting before accepting connections Receive-only mode excludes stdin from the descriptor list, but the listen loop still requires more than one descriptor. A receive-only listener with a single listening socket therefore exits before accepting a connection. Account for the missing stdin descriptor. Fixes: b408fc243ce2 ("Ignore stdin with --recv-only") --- ncat/ncat_listen.c | 4 +++- ncat/test/ncat-test.pl | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ncat/ncat_listen.c b/ncat/ncat_listen.c index 9343ee4c4..5450b2f08 100644 --- a/ncat/ncat_listen.c +++ b/ncat/ncat_listen.c @@ -409,7 +409,9 @@ int ncat_listen() init_fdlist(&broadcast_fdlist, o.conn_limit); - while (!breakloop && (client_fdlist.nfds > 1 || get_conn_count() > 0)) { + /* Receive-only mode does not add stdin to the descriptor list. */ + while (!breakloop && (client_fdlist.nfds > (o.recvonly ? 0 : 1) + || get_conn_count() > 0)) { long usec_wait = -1; tvp = NULL; /* We pass these temporary descriptor sets to fselect, since fselect diff --git a/ncat/test/ncat-test.pl b/ncat/test/ncat-test.pl index 422767a92..e5f89ef0c 100755 --- a/ncat/test/ncat-test.pl +++ b/ncat/test/ncat-test.pl @@ -1075,6 +1075,20 @@ server_client_test_tcp_sctp_ssl "--recv-only server closes stdout and stops runn ["--recv-only"], [], eof_test("Server", 1, "socket"); kill_children; +# Receive-only listeners must work with either address family on its own. +for my $binding (["-4", "IPv4"], ["-6", "IPv6"]) { + my ($family, $description) = @$binding; + + server_client_test_tcp_ssl "--recv-only server receives data over $description", + ["--recv-only", $family], [$family, "--send-only"], sub { + syswrite($c_in, "abc\n"); + close($c_in); + + my $resp = timeout_read($s_out) or die "Read timeout"; + $resp eq "abc\n" or die "Server got " . d($resp); + }; +} + # Tests to check that server defaults to non-persistent without --keep-open. # Server immediately quits after the first connection closed without --keep-open