Fix of CVE-2017-18350

Adapted from bitcoin/bitcoin#11397 by Wladimir J. van der Laan.

Co-Authored-By: Jack Grigg <jack@electriccoin.co>
Co-Authored-By: Daira Hopwood <daira@electriccoin.co>
This commit is contained in:
Sean Bowe
2019-11-08 09:16:50 -07:00
committed by Jonathan "Duke" Leto
parent 3252efc837
commit f69e3697aa

View File

@@ -267,7 +267,7 @@ struct timeval MillisToTimeval(int64_t nTimeout)
* *
* @note This function requires that hSocket is in non-blocking mode. * @note This function requires that hSocket is in non-blocking mode.
*/ */
bool static InterruptibleRecv(char* data, size_t len, int timeout, SOCKET& hSocket) bool static InterruptibleRecv(uint8_t* data, size_t len, int timeout, SOCKET& hSocket)
{ {
int64_t curTime = GetTimeMillis(); int64_t curTime = GetTimeMillis();
int64_t endTime = curTime + timeout; int64_t endTime = curTime + timeout;
@@ -335,7 +335,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials
CloseSocket(hSocket); CloseSocket(hSocket);
return error("Error sending to proxy"); return error("Error sending to proxy");
} }
char pchRet1[2]; uint8_t pchRet1[2];
if (!InterruptibleRecv(pchRet1, 2, SOCKS5_RECV_TIMEOUT, hSocket)) { if (!InterruptibleRecv(pchRet1, 2, SOCKS5_RECV_TIMEOUT, hSocket)) {
CloseSocket(hSocket); CloseSocket(hSocket);
return error("Error reading proxy response"); return error("Error reading proxy response");
@@ -360,7 +360,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials
return error("Error sending authentication to proxy"); return error("Error sending authentication to proxy");
} }
LogPrint("proxy", "SOCKS5 sending proxy authentication %s:%s\n", auth->username, auth->password); LogPrint("proxy", "SOCKS5 sending proxy authentication %s:%s\n", auth->username, auth->password);
char pchRetA[2]; uint8_t pchRetA[2];
if (!InterruptibleRecv(pchRetA, 2, SOCKS5_RECV_TIMEOUT, hSocket)) { if (!InterruptibleRecv(pchRetA, 2, SOCKS5_RECV_TIMEOUT, hSocket)) {
CloseSocket(hSocket); CloseSocket(hSocket);
return error("Error reading proxy authentication response"); return error("Error reading proxy authentication response");
@@ -389,7 +389,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials
CloseSocket(hSocket); CloseSocket(hSocket);
return error("Error sending to proxy"); return error("Error sending to proxy");
} }
char pchRet2[4]; uint8_t pchRet2[4];
if (!InterruptibleRecv(pchRet2, 4, SOCKS5_RECV_TIMEOUT, hSocket)) { if (!InterruptibleRecv(pchRet2, 4, SOCKS5_RECV_TIMEOUT, hSocket)) {
CloseSocket(hSocket); CloseSocket(hSocket);
return error("Error reading proxy response"); return error("Error reading proxy response");
@@ -417,7 +417,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials
CloseSocket(hSocket); CloseSocket(hSocket);
return error("Error: malformed proxy response"); return error("Error: malformed proxy response");
} }
char pchRet3[256]; uint8_t pchRet3[256];
switch (pchRet2[3]) switch (pchRet2[3])
{ {
case 0x01: ret = InterruptibleRecv(pchRet3, 4, SOCKS5_RECV_TIMEOUT, hSocket); break; case 0x01: ret = InterruptibleRecv(pchRet3, 4, SOCKS5_RECV_TIMEOUT, hSocket); break;
@@ -429,7 +429,7 @@ static bool Socks5(const std::string& strDest, int port, const ProxyCredentials
CloseSocket(hSocket); CloseSocket(hSocket);
return error("Error reading from proxy"); return error("Error reading from proxy");
} }
int nRecv = pchRet3[0]; size_t nRecv = pchRet3[0];
ret = InterruptibleRecv(pchRet3, nRecv, SOCKS5_RECV_TIMEOUT, hSocket); ret = InterruptibleRecv(pchRet3, nRecv, SOCKS5_RECV_TIMEOUT, hSocket);
break; break;
} }