Control: tag -1 - upstream Hi Duncan,
On Sun, 08 Mar 2020 at 14:25:50 +1100, Duncan Roe wrote:
>> The enclosed patch seems to work for me. (Untested though, so not
>> pushing just yet.)
>
> Good idea not to apply that patch. After applying, I can send server nc into a
> hard loop by entering ^D after it has responded to the its 2nd client, as per
> attached scenario.
>
> Should be a simple fix.
Thanks for testing and fixing the patch :-) I'm reattaching what you
sent me privately so it shows in the BTS.
> Using TCP, ^D to server nc has no visible efect. Maybe an update to your patch
> can fix this also. I will investicate over the next few days.
Sorry, my bad for claiming earlier that ‘-q0’ was an alias ‘-N’. What's
correct is what's written in the manual, namely that it *implies* ‘-N’.
All ‘-N’ does is to call shutdown(2) after EOF on stdin; which it does,
so I'm removing the ‘upstream’ tag on the bug.
> Input in parentheses
>
> Screen 1 Screen 2
> 13:40:42$ (nc -k -u -N -6 -l ::1 1042)
> 13:42:11$ (nc -u -N -6 ::1 1042)
> (aaa)
> aaa
> (^D)
> 13:42:50$
> (nc -u -N -6 ::1 1042)
> (bbb)
> bbb
> (^D)
>
> Screen 2 nc is now in a hard loop:
>
>> poll([{fd=0, events=POLLIN}, {fd=3, events=0}, {fd=3, events=POLLIN}, {fd=1,
>> events=0}], 4, -1) = 2 ([{fd=3, revents=POLLHUP}, {fd=3,
>> revents=POLLIN|POLLHUP}])
>> shutdown(3, SHUT_WR) = -1 ENOTCONN (Transport endpoint is
>> not connected)
>> read(3, "", 16384) = 0
>> shutdown(3, SHUT_RD) = -1 ENOTCONN (Transport endpoint is
>> not connected)
>> poll([{fd=0, events=POLLIN}, {fd=3, events=0}, {fd=3, events=POLLIN}, {fd=1,
>> events=0}], 4, -1) = 2 ([{fd=3, revents=POLLHUP}, {fd=3,
>> revents=POLLIN|POLLHUP}])
>> shutdown(3, SHUT_WR) = -1 ENOTCONN (Transport endpoint is
>> not connected)
--
Guilhem.
--- a/netcat.c
+++ b/netcat.c
@@ -1431,8 +1431,11 @@ readwrite(int net_fd)
/* both inputs are gone, buffers are empty, we are done */
if (pfd[POLL_STDIN].fd == -1 && pfd[POLL_NETIN].fd == -1 &&
stdinbufpos == 0 && netinbufpos == 0) {
- if (qflag <= 0)
+ if (qflag <= 0) {
+ if (kflag)
+ kflag = 0;
return;
+ }
goto delay_exit;
}
/* both outputs are gone, we can't continue */
@@ -1607,6 +1610,10 @@ delay_exit:
if (pfd[POLL_NETOUT].fd != -1 && Nflag)
shutdown(pfd[POLL_NETOUT].fd, SHUT_WR);
pfd[POLL_NETOUT].fd = -1;
+ if (uflag && pfd[POLL_NETIN].fd != -1 && Nflag && netinbufpos == 0) {
+ shutdown(pfd[POLL_NETIN].fd, SHUT_RD);
+ pfd[POLL_NETIN].fd = -1;
+ }
}
/* net in gone and queue empty? */
if (pfd[POLL_NETIN].fd == -1 && netinbufpos == 0) {
signature.asc
Description: PGP signature

