1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-11 12:05:06 -05:00

lib/socks.c: Avoid type conversions where possible

Streamlined variable names and types to avoid type conversions that
may result in data being lost on non 32-bit systems.
This commit is contained in:
Marc Hoersken 2012-10-04 20:17:49 +02:00
parent 90821c6202
commit cd423348d9

View File

@ -370,8 +370,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
long timeout;
bool socks5_resolve_local = (conn->proxytype == CURLPROXY_SOCKS5)?TRUE:FALSE;
const size_t hostname_len = strlen(hostname);
ssize_t packetsize = 0;
int len;
ssize_t len = 0, packetsize = 0;
/* RFC1928 chapter 5 specifies max 255 chars for domain name in packet */
if(!socks5_resolve_local && hostname_len > 255) {
@ -474,14 +473,14 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
#endif
else if(socksreq[1] == 2) {
/* Needs user name and password */
size_t userlen, pwlen;
size_t proxy_name_len, proxy_password_len;
if(proxy_name && proxy_password) {
userlen = strlen(proxy_name);
pwlen = strlen(proxy_password);
proxy_name_len = strlen(proxy_name);
proxy_password_len = strlen(proxy_password);
}
else {
userlen = 0;
pwlen = 0;
proxy_name_len = 0;
proxy_password_len = 0;
}
/* username/password request looks like
@ -493,14 +492,14 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
*/
len = 0;
socksreq[len++] = 1; /* username/pw subnegotiation version */
socksreq[len++] = (unsigned char) userlen;
if(proxy_name && userlen)
memcpy(socksreq + len, proxy_name, userlen);
len += (int)userlen;
socksreq[len++] = (unsigned char) pwlen;
if(proxy_password && pwlen)
memcpy(socksreq + len, proxy_password, pwlen);
len += (int)pwlen;
socksreq[len++] = (unsigned char) proxy_name_len;
if(proxy_name && proxy_name_len)
memcpy(socksreq + len, proxy_name, proxy_name_len);
len += proxy_name_len;
socksreq[len++] = (unsigned char) proxy_password_len;
if(proxy_password && proxy_password_len)
memcpy(socksreq + len, proxy_password, proxy_password_len);
len += proxy_password_len;
code = Curl_write_plain(conn, sock, (char *)socksreq, len, &written);
if((code != CURLE_OK) || (len != written)) {
@ -563,7 +562,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
socksreq[len++] = 3; /* ATYP: domain name = 3 */
socksreq[len++] = (char) hostname_len; /* address length */
memcpy(&socksreq[len], hostname, hostname_len); /* address str w/o NULL */
len += (int)hostname_len;
len += hostname_len;
}
else {
struct Curl_dns_entry *dns;