From 9dda666d8da8fe5c848606b3758758b264327d71 Mon Sep 17 00:00:00 2001 From: z3APA3A <3APA3A@3proxy.ru> Date: Mon, 4 Jan 2016 01:30:49 +0300 Subject: [PATCH] minor changes in clientnegotiate() 1. Use [] for hostname in form of IPv6 address 2. Remove large buffer from stack --- src/auth.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/auth.c b/src/auth.c index 0667595..9033bda 100644 --- a/src/auth.c +++ b/src/auth.c @@ -10,7 +10,8 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct sockaddr * addr){ - unsigned char buf[1024]; + unsigned char *buf; + unsigned char *username; int res; int len=0; unsigned char * user, *pass; @@ -18,6 +19,13 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc user = redir->extuser; pass = redir->extpass; + if (param->srvinbuf < 4096){ + if(param->srvbuf)myfree(param->srvbuf); + param->srvbuf = myalloc(4096); + param->srvbufsize = 4096; + } + buf = param->srvbuf; + username = buf + 2048; if(user) { if (*user == '*') { if(!param->username) return 4; @@ -34,7 +42,11 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc { len = sprintf((char *)buf, "CONNECT "); if(redir->type == R_CONNECTP && param->hostname) { + char * needreplace; + needreplace = strchr(param->hostname, ':'); + if(needreplace) buf[len++] = '['; len =+ sprintf((char *)buf + len, "%.256s", param->hostname); + if(needreplace) buf[len++] = ']'; } else { if(*SAFAMILY(addr) == AF_INET6) buf[len++] = '['; @@ -44,7 +56,6 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc len += sprintf((char *)buf + len, ":%hu HTTP/1.0\r\nProxy-Connection: keep-alive\r\n", ntohs(*SAPORT(addr))); if(user){ - unsigned char username[256]; len += sprintf((char *)buf + len, "Proxy-authorization: basic "); sprintf((char *)username, "%.128s:%.64s", user, pass?pass:(unsigned char *)""); en64(username, buf+len, (int)strlen((char *)username));