[PATCH] mux: fix incorrect return value check in local forward cancellation

Boris Tonofa boris.afonot at gmail.com
Sat Jun 21 05:28:33 AEST 2025


Hi,

This patch fixes a logic error in mux_master_process_close_fwd().

channel_cancel_lport_listener() returns 1 on success and 0 on failure.
The previous code incorrectly checked for `== -1`, a value the function
never returns, so failure was not detected and the "port not found"
error message was never shown when cancelling dynamic or local port
forwards.

The patch applies cleanly to current master and all GitHub CI jobs are
green (see mirror PR):
   https://github.com/openssh/openssh-portable/pull/577

If merged, could you please keep the author line
    From: Boris Tonofa <b.tonofa at ideco.ru>
in the commit message?  My company would appreciate the attribution.

Thanks for your time and review.

Best regards,
Boris


 From 41aacbdbf107bebae150a46bd098d4ed1f379019 Mon Sep 17 00:00:00 2001
From: Boris Tonofa <b.tonofa at ideco.ru>
Date: Fri, 20 Jun 2025 19:22:14 +0300
Subject: [PATCH] mux: fix incorrect return value check in local forward
  cancellation

channel_cancel_lport_listener() returns 1 on success and 0 on failure.
The previous code incorrectly checked for `== -1`, a value the function
never returns, so failure was not detected and the "port not found"
error message was never shown when cancelling dynamic or local port
forwards.
---
  mux.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mux.c b/mux.c
index 415024f74..ad40b4489 100644
--- a/mux.c
+++ b/mux.c
@@ -931,7 +931,7 @@ mux_master_process_close_fwd(struct ssh *ssh, u_int rid,
  	} else {	/* local and dynamic forwards */
  		/* Ditto */
  		if (channel_cancel_lport_listener(ssh, &fwd, fwd.connect_port,
-		    &options.fwd_opts) == -1)
+		    &options.fwd_opts) != 1)
  			error_reason = "port not found";
  	}

-- 
2.47.0


More information about the openssh-unix-dev mailing list