mirror of
https://github.com/curl/curl.git
synced 2026-08-24 20:13:35 +03:00
socks: reject zero-length GSSAPI/SSPI tokens from proxy
A "broken" SOCKS5 proxy can send an invalid length of the encryption token, which could cause malloc(0) to be called, which is a "platform can do what it wants" potential problem. Resolve this by explicitly checking the length and rejecting the invalid token before ever attempting to allocate any memory. Closes #21159
This commit is contained in:
parent
930f2e8227
commit
fb6925c243
2 changed files with 23 additions and 0 deletions
|
|
@ -266,6 +266,13 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf,
|
|||
memcpy(&us_length, socksreq + 2, sizeof(short));
|
||||
us_length = ntohs(us_length);
|
||||
|
||||
if(!us_length) {
|
||||
failf(data, "Invalid zero-length GSS-API authentication token.");
|
||||
gss_release_name(&gss_status, &server);
|
||||
Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL);
|
||||
return CURLE_COULDNT_CONNECT;
|
||||
}
|
||||
|
||||
gss_recv_token.length = us_length;
|
||||
gss_recv_token.value = curlx_malloc(gss_recv_token.length);
|
||||
if(!gss_recv_token.value) {
|
||||
|
|
@ -453,6 +460,12 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf,
|
|||
memcpy(&us_length, socksreq + 2, sizeof(short));
|
||||
us_length = ntohs(us_length);
|
||||
|
||||
if(!us_length) {
|
||||
failf(data, "Invalid zero-length GSS-API encryption token.");
|
||||
Curl_gss_delete_sec_context(&gss_status, &gss_context, NULL);
|
||||
return CURLE_COULDNT_CONNECT;
|
||||
}
|
||||
|
||||
gss_recv_token.length = us_length;
|
||||
gss_recv_token.value = curlx_malloc(gss_recv_token.length);
|
||||
if(!gss_recv_token.value) {
|
||||
|
|
|
|||
|
|
@ -223,6 +223,11 @@ static CURLcode socks5_sspi_loop(struct Curl_cfilter *cf,
|
|||
memcpy(&us_length, socksreq + 2, sizeof(short));
|
||||
us_length = ntohs(us_length);
|
||||
|
||||
if(!us_length) {
|
||||
failf(data, "Invalid zero-length SSPI authentication token.");
|
||||
return CURLE_COULDNT_CONNECT;
|
||||
}
|
||||
|
||||
sspi_recv_token.cbBuffer = us_length;
|
||||
sspi_recv_token.pvBuffer = curlx_malloc(us_length);
|
||||
|
||||
|
|
@ -400,6 +405,11 @@ static CURLcode socks5_sspi_encrypt(struct Curl_cfilter *cf,
|
|||
memcpy(&us_length, socksreq + 2, sizeof(short));
|
||||
us_length = ntohs(us_length);
|
||||
|
||||
if(!us_length) {
|
||||
failf(data, "Invalid zero-length SSPI encryption token.");
|
||||
return CURLE_COULDNT_CONNECT;
|
||||
}
|
||||
|
||||
sspi_w_token[0].cbBuffer = us_length;
|
||||
sspi_w_token[0].pvBuffer = curlx_malloc(us_length);
|
||||
if(!sspi_w_token[0].pvBuffer)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue