Skip to content

Fix cancelling server TCP listeners#414

Merged
mkj merged 3 commits intomasterfrom
pr/cancel-tcp-fwd
Apr 14, 2026
Merged

Fix cancelling server TCP listeners#414
mkj merged 3 commits intomasterfrom
pr/cancel-tcp-fwd

Conversation

@mkj
Copy link
Copy Markdown
Owner

@mkj mkj commented Apr 13, 2026

There are three bugs involved here.

get_listener() only tested the first element in the list rather than
iterating. This was incorrect when first written in
444dbb5 ("- Reworked non-channel fd handling to listener.c - More channel cleaning up")

tcpinfo.chantype isn't initialised in svr_cancelremotetcp(), so
matchtcp() never succeeded. The chantype comparison is unnecessary
(LISTENER_TYPE_TCPFORWARDED has already been checked), so remove it.

matchtcp() was comparing with listenaddr, but that will be NULL
when listening on localhost, logic in svr_remotetcpreq().
This codepath previously couldn't be reached due to the chantype test.
That regressed in 1984aab ("Server shouldn't return "localhost" in response to -R forward connections if that wasn't what the client requested.")

A testcase is added.

Fixes #412, fixes #413

@mkj mkj force-pushed the pr/cancel-tcp-fwd branch from 455457b to 320186b Compare April 13, 2026 15:14
mkj added 3 commits April 13, 2026 23:33
A segfault in a server child process wouldn't have been detected.
This detection is simple but seems adequate.
This has no functional effect, but improves the innacurate comment on
the Listener "type" field.
There are three bugs involved here.

get_listener() only tested the first element in the list rather than
iterating.  This was incorrect when first written in
444dbb5 ("- Reworked non-channel fd handling to listener.c - More channel cleaning up")

tcpinfo.chantype isn't initialised in svr_cancelremotetcp(), so
matchtcp() never succeeded. The chantype comparison is unnecessary
(LISTENER_TYPE_TCPFORWARDED has already been checked), so remove it.

matchtcp() was comparing with listenaddr, but that will be NULL
when listening on localhost, logic in svr_remotetcpreq().
That regressed in 1984aab ("Server shouldn't return "localhost" in response to -R forward connections if that wasn't what the client requested.")
The NULL pointer previously couldn't be reached due to the chantype
problem mentioned above.

A testcase is added.

Fixes #412, fixes #413
@mkj mkj force-pushed the pr/cancel-tcp-fwd branch from 320186b to f5d4440 Compare April 13, 2026 15:34
@mkj mkj merged commit f5d4440 into master Apr 14, 2026
18 checks passed
@mkj mkj deleted the pr/cancel-tcp-fwd branch April 16, 2026 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

svr-tcpfwd.c: match and svr_cancelremotetcp inconsistency causing cancellation to fail maybe Possible logic bug in listener.c

1 participant