mirror of
https://github.com/curl/curl.git
synced 2025-01-30 14:22:33 +08:00
socks: better buffer size checks for socks4a user and hostname
Also limit the proxy user name to 255 bytes, which is the same limit as in SOCKS5. Reported-by: sd0 on hackerone Closes #12139
This commit is contained in:
parent
0b6d9ac8d9
commit
01057d6161
10
lib/socks.c
10
lib/socks.c
@ -402,8 +402,11 @@ CONNECT_REQ_INIT:
|
|||||||
socksreq[8] = 0; /* ensure empty userid is NUL-terminated */
|
socksreq[8] = 0; /* ensure empty userid is NUL-terminated */
|
||||||
if(sx->proxy_user) {
|
if(sx->proxy_user) {
|
||||||
size_t plen = strlen(sx->proxy_user);
|
size_t plen = strlen(sx->proxy_user);
|
||||||
if(plen >= (size_t)data->set.buffer_size - 8) {
|
if(plen > 255) {
|
||||||
failf(data, "Too long SOCKS proxy user name, can't use");
|
/* there is no real size limit to this field in the protocol, but
|
||||||
|
SOCKS5 limits the proxy user field to 255 bytes and it seems likely
|
||||||
|
that a longer field is either a mistake or malicous input */
|
||||||
|
failf(data, "Too long SOCKS proxy user name");
|
||||||
return CURLPX_LONG_USER;
|
return CURLPX_LONG_USER;
|
||||||
}
|
}
|
||||||
/* copy the proxy name WITH trailing zero */
|
/* copy the proxy name WITH trailing zero */
|
||||||
@ -426,7 +429,8 @@ CONNECT_REQ_INIT:
|
|||||||
socksreq[7] = 1;
|
socksreq[7] = 1;
|
||||||
/* append hostname */
|
/* append hostname */
|
||||||
hostnamelen = strlen(sx->hostname) + 1; /* length including NUL */
|
hostnamelen = strlen(sx->hostname) + 1; /* length including NUL */
|
||||||
if(hostnamelen <= 255)
|
if((hostnamelen <= 255) &&
|
||||||
|
(packetsize + hostnamelen < data->set.buffer_size))
|
||||||
strcpy((char *)socksreq + packetsize, sx->hostname);
|
strcpy((char *)socksreq + packetsize, sx->hostname);
|
||||||
else {
|
else {
|
||||||
failf(data, "SOCKS4: too long host name");
|
failf(data, "SOCKS4: too long host name");
|
||||||
|
Loading…
Reference in New Issue
Block a user