fix socks5 bug: always requested user auth cap

since "user" always points to a statically allocated string buffer,
the test for if(user)... was bogus.
use ulen instead.

this bug should only be visible on socks servers that require auth
if username was not passed, so it was probably not really an issue.
This commit is contained in:
rofl0r 2015-06-14 12:07:19 +01:00
parent d900b090fe
commit 9969dd3a22

View File

@ -227,7 +227,7 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
#define HTTP_AUTH_MAX ((0xFF * 2) + 1 + 1) /* 2 * 0xff: username and pass, plus 1 for ':' and 1 for zero terminator. */ #define HTTP_AUTH_MAX ((0xFF * 2) + 1 + 1) /* 2 * 0xff: username and pass, plus 1 for ':' and 1 for zero terminator. */
char src[HTTP_AUTH_MAX]; char src[HTTP_AUTH_MAX];
char dst[(4 * HTTP_AUTH_MAX)]; char dst[(4 * HTTP_AUTH_MAX)];
if(user[0]) { if(ulen) {
snprintf(src, sizeof(src), "%s:%s", user, pass); snprintf(src, sizeof(src), "%s:%s", user, pass);
encode_base_64(src, dst, sizeof(dst)); encode_base_64(src, dst, sizeof(dst));
} else dst[0] = 0; } else dst[0] = 0;
@ -235,8 +235,8 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
len = snprintf((char *) buff, sizeof(buff), len = snprintf((char *) buff, sizeof(buff),
"CONNECT %s:%d HTTP/1.0\r\n%s%s%s\r\n", "CONNECT %s:%d HTTP/1.0\r\n%s%s%s\r\n",
dns_name, ntohs(port), dns_name, ntohs(port),
user[0] ? "Proxy-Authorization: Basic " : dst, ulen ? "Proxy-Authorization: Basic " : dst,
dst, user[0] ? "\r\n" : dst); dst, ulen ? "\r\n" : dst);
if(len != send(sock, buff, len, 0)) if(len != send(sock, buff, len, 0))
goto err; goto err;
@ -300,11 +300,11 @@ static int tunnel_to(int sock, ip_type ip, unsigned short port, proxy_type pt, c
} }
break; break;
case SOCKS5_TYPE:{ case SOCKS5_TYPE:{
int n_methods = user ? 2 : 1; int n_methods = ulen ? 2 : 1;
buff[0] = 5; // version buff[0] = 5; // version
buff[1] = n_methods ; // number of methods buff[1] = n_methods ; // number of methods
buff[2] = 0; // no auth method buff[2] = 0; // no auth method
if(user) buff[3] = 2; /// auth method -> username / password if(ulen) buff[3] = 2; /// auth method -> username / password
if(2+n_methods != write_n_bytes(sock, (char *) buff, 2+n_methods)) if(2+n_methods != write_n_bytes(sock, (char *) buff, 2+n_methods))
goto err; goto err;