From 6a15a576b996f2c944ef4521157cf196a1fbdb98 Mon Sep 17 00:00:00 2001 From: netms7 <94935557+netms7@users.noreply.github.com> Date: Thu, 25 Nov 2021 00:32:41 +0100 Subject: [PATCH] Fix reading domain name of incorrect length Fixed a bug that causes SOCKS 5 proxy 59 error due to reading hostname of incorrect length. --- src/auth.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/auth.c b/src/auth.c index d00c1f6..f0029ad 100644 --- a/src/auth.c +++ b/src/auth.c @@ -195,8 +195,13 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc break; return 59; case 3: - if (sockgetlinebuf(param, SERVER, buf, 1, EOF, conf.timeouts[CHAIN_TO]) != 1) return 59; - if (sockgetlinebuf(param, SERVER, buf, (unsigned)(buf[0]+2), EOF, conf.timeouts[CHAIN_TO]) != (unsigned)(buf[0]+2)) return 59; + if (sockgetlinebuf(param, SERVER, buf, 1, EOF, conf.timeouts[CHAIN_TO]) != 1) + return 59; + + const unsigned hostname_length = buf[0]; + + if (sockgetlinebuf(param, SERVER, buf, hostname_length + 2, EOF, conf.timeouts[CHAIN_TO]) != hostname_length + 2) + return 59; break; case 4: if (sockgetlinebuf(param, SERVER, buf, 18, EOF, conf.timeouts[CHAIN_TO]) == 18)