From 91adfb5917d31a7c29d6c0536f1e301542577e81 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 17 Jan 2022 12:08:16 +0000 Subject: Fix handling invalid ports. Instead of wrapping around, which is not behaviour any reasonable user would expect, just use the default port if above 65535. Disallow connecting on port 0. This port has special meaning and servers can not listen on it. It is more likely the user just gave an invalid value to the port field as atoi("invalid") == 0. --- src/common/server.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/common/server.c b/src/common/server.c index f90ce28f..c2965eb3 100644 --- a/src/common/server.c +++ b/src/common/server.c @@ -1559,7 +1559,7 @@ server_connect (server *serv, char *hostname, int port, int no_login) if (!hostname[0]) return; - if (port < 0) + if (port < 1 || port > 65535) { /* use default port for this server type */ port = 6667; @@ -1568,7 +1568,6 @@ server_connect (server *serv, char *hostname, int port, int no_login) port = 6697; #endif } - port &= 0xffff; /* wrap around */ if (serv->connected || serv->connecting || serv->recondelay_tag) server_disconnect (sess, TRUE, -1); -- cgit 1.4.1