diff options
author | Marc Hoersken <info@marc-hoersken.de> | 2012-10-04 20:17:49 +0200 |
---|---|---|
committer | Marc Hoersken <info@marc-hoersken.de> | 2012-10-04 20:17:49 +0200 |
commit | cd423348d9b72d57a79469d2465b48972c28baf7 (patch) | |
tree | 9d471a275922c1b61cef7422891b046655357c12 /lib/socks.c | |
parent | 90821c62027f4fc4259642ab1b5af8157ae40054 (diff) | |
download | curl-cd423348d9b72d57a79469d2465b48972c28baf7.tar.gz |
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.
Diffstat (limited to 'lib/socks.c')
-rw-r--r-- | lib/socks.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/lib/socks.c b/lib/socks.c index 399256726..2d6e4a013 100644 --- a/lib/socks.c +++ b/lib/socks.c @@ -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; |