summaryrefslogtreecommitdiff
path: root/lib/socks.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2021-01-19 15:30:59 +0100
committerDaniel Stenberg <daniel@haxx.se>2021-01-20 08:54:19 +0100
commitd0688dcbdf412273e276dd29135b952f2065cb5b (patch)
treed7f684daa6f5cdec76d93634a1a327eff858cea2 /lib/socks.c
parent942cf12c2f73c4bb13858acc9101b1d644bf7c50 (diff)
downloadcurl-d0688dcbdf412273e276dd29135b952f2065cb5b.tar.gz
socks: use the download buffer instead
The SOCKS code now uses the generic download buffer for temporary storage during the connection procedure, instead of having its own private 600 byte buffer that adds to the connectdata struct size. This works fine because this point the buffer is allocated but is not use for download yet since the connection hasn't completed. This reduces the connection struct size by 22% on a 64bit arch! The SOCKS buffer needs to be at least 600 bytes, and the download buffer is guaranteed to never be smaller than 1000 bytes. Closes #6491
Diffstat (limited to 'lib/socks.c')
-rw-r--r--lib/socks.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/socks.c b/lib/socks.c
index 64b04dd68..9252e2c17 100644
--- a/lib/socks.c
+++ b/lib/socks.c
@@ -195,7 +195,7 @@ CURLproxycode Curl_SOCKS4(const char *proxy_user,
struct connectdata *conn = data->conn;
const bool protocol4a =
(conn->socks_proxy.proxytype == CURLPROXY_SOCKS4A) ? TRUE : FALSE;
- unsigned char *socksreq = &conn->cnnct.socksreq[0];
+ unsigned char *socksreq = (unsigned char *)data->state.buffer;
CURLcode result;
curl_socket_t sockfd = conn->sock[sockindex];
struct connstate *sx = &conn->cnnct;
@@ -203,6 +203,9 @@ CURLproxycode Curl_SOCKS4(const char *proxy_user,
ssize_t actualread;
ssize_t written;
+ /* make sure that the buffer is at least 600 bytes */
+ DEBUGASSERT(READBUFFER_MIN >= 600);
+
if(!SOCKS_STATE(sx->state) && !*done)
sxstate(data, CONNECT_SOCKS_INIT);
@@ -319,7 +322,7 @@ CURLproxycode Curl_SOCKS4(const char *proxy_user,
socksreq[8] = 0; /* ensure empty userid is NUL-terminated */
if(proxy_user) {
size_t plen = strlen(proxy_user);
- if(plen >= sizeof(sx->socksreq) - 8) {
+ if(plen >= (size_t)data->set.buffer_size - 8) {
failf(data, "Too long SOCKS proxy user name, can't use!");
return CURLPX_LONG_USER;
}
@@ -438,8 +441,7 @@ CURLproxycode Curl_SOCKS4(const char *proxy_user,
failf(data,
"Can't complete SOCKS4 connection to %d.%d.%d.%d:%d. (%d)"
", request rejected or failed.",
- (unsigned char)socksreq[4], (unsigned char)socksreq[5],
- (unsigned char)socksreq[6], (unsigned char)socksreq[7],
+ socksreq[4], socksreq[5], socksreq[6], socksreq[7],
(((unsigned char)socksreq[2] << 8) | (unsigned char)socksreq[3]),
(unsigned char)socksreq[1]);
return CURLPX_REQUEST_FAILED;
@@ -448,8 +450,7 @@ CURLproxycode Curl_SOCKS4(const char *proxy_user,
"Can't complete SOCKS4 connection to %d.%d.%d.%d:%d. (%d)"
", request rejected because SOCKS server cannot connect to "
"identd on the client.",
- (unsigned char)socksreq[4], (unsigned char)socksreq[5],
- (unsigned char)socksreq[6], (unsigned char)socksreq[7],
+ socksreq[4], socksreq[5], socksreq[6], socksreq[7],
(((unsigned char)socksreq[2] << 8) | (unsigned char)socksreq[3]),
(unsigned char)socksreq[1]);
return CURLPX_IDENTD;
@@ -458,8 +459,7 @@ CURLproxycode Curl_SOCKS4(const char *proxy_user,
"Can't complete SOCKS4 connection to %d.%d.%d.%d:%d. (%d)"
", request rejected because the client program and identd "
"report different user-ids.",
- (unsigned char)socksreq[4], (unsigned char)socksreq[5],
- (unsigned char)socksreq[6], (unsigned char)socksreq[7],
+ socksreq[4], socksreq[5], socksreq[6], socksreq[7],
(((unsigned char)socksreq[2] << 8) | (unsigned char)socksreq[3]),
(unsigned char)socksreq[1]);
return CURLPX_IDENTD_DIFFER;
@@ -467,8 +467,7 @@ CURLproxycode Curl_SOCKS4(const char *proxy_user,
failf(data,
"Can't complete SOCKS4 connection to %d.%d.%d.%d:%d. (%d)"
", Unknown.",
- (unsigned char)socksreq[4], (unsigned char)socksreq[5],
- (unsigned char)socksreq[6], (unsigned char)socksreq[7],
+ socksreq[4], socksreq[5], socksreq[6], socksreq[7],
(((unsigned char)socksreq[2] << 8) | (unsigned char)socksreq[3]),
(unsigned char)socksreq[1]);
return CURLPX_UNKNOWN_FAIL;
@@ -507,7 +506,7 @@ CURLproxycode Curl_SOCKS5(const char *proxy_user,
o X'00' succeeded
*/
struct connectdata *conn = data->conn;
- unsigned char *socksreq = &conn->cnnct.socksreq[0];
+ unsigned char *socksreq = (unsigned char *)data->state.buffer;
char dest[256] = "unknown"; /* printable hostname:port */
int idx;
ssize_t actualread;