Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

lib/socks.c: Merged two size variables into one

  • Loading branch information...
commit 07593b242296e43c23aee1717bdb84426a6b230a 1 parent cd42334
Marc Hörsken mback2k authored

Showing 1 changed file with 15 additions and 16 deletions. Show diff stats Hide diff stats

  1. +15 16 lib/socks.c
31 lib/socks.c
@@ -370,7 +370,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
370 370 long timeout;
371 371 bool socks5_resolve_local = (conn->proxytype == CURLPROXY_SOCKS5)?TRUE:FALSE;
372 372 const size_t hostname_len = strlen(hostname);
373   - ssize_t len = 0, packetsize = 0;
  373 + ssize_t len = 0;
374 374
375 375 /* RFC1928 chapter 5 specifies max 255 chars for domain name in packet */
376 376 if(!socks5_resolve_local && hostname_len > 255) {
@@ -626,22 +626,20 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
626 626 socksreq[len++] = (unsigned char)((remote_port >> 8) & 0xff); /* PORT MSB */
627 627 socksreq[len++] = (unsigned char)(remote_port & 0xff); /* PORT LSB */
628 628
629   - packetsize = len;
630   -
631 629 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
632 630 if(conn->socks5_gssapi_enctype) {
633 631 failf(data, "SOCKS5 gssapi protection not yet implemented.");
634 632 }
635 633 else
636 634 #endif
637   - code = Curl_write_plain(conn, sock, (char *)socksreq, packetsize,
638   - &written);
639   - if((code != CURLE_OK) || (written != packetsize)) {
  635 + code = Curl_write_plain(conn, sock, (char *)socksreq, len, &written);
  636 +
  637 + if((code != CURLE_OK) || (len != written)) {
640 638 failf(data, "Failed to send SOCKS5 connect request.");
641 639 return CURLE_COULDNT_CONNECT;
642 640 }
643 641
644   - packetsize = 10; /* minimum packet size is 10 */
  642 + len = 10; /* minimum packet size is 10 */
645 643
646 644 #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
647 645 if(conn->socks5_gssapi_enctype) {
@@ -649,9 +647,10 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
649 647 }
650 648 else
651 649 #endif
652   - result = Curl_blockread_all(conn, sock, (char *)socksreq, packetsize,
653   - &actualread);
654   - if((result != CURLE_OK) || (actualread != packetsize)) {
  650 + result = Curl_blockread_all(conn, sock, (char *)socksreq,
  651 + len, &actualread);
  652 +
  653 + if((result != CURLE_OK) || (len != actualread)) {
655 654 failf(data, "Failed to receive SOCKS5 connect request ack.");
656 655 return CURLE_COULDNT_CONNECT;
657 656 }
@@ -715,11 +714,11 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
715 714 if(socksreq[3] == 3) {
716 715 /* domain name */
717 716 int addrlen = (int) socksreq[4];
718   - packetsize = 5 + addrlen + 2;
  717 + len = 5 + addrlen + 2;
719 718 }
720 719 else if(socksreq[3] == 4) {
721 720 /* IPv6 */
722   - packetsize = 4 + 16 + 2;
  721 + len = 4 + 16 + 2;
723 722 }
724 723
725 724 /* At this point we already read first 10 bytes */
@@ -727,11 +726,11 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
727 726 if(!conn->socks5_gssapi_enctype) {
728 727 /* decrypt_gssapi_blockread already read the whole packet */
729 728 #endif
730   - if(packetsize > 10) {
731   - packetsize -= 10;
  729 + if(len > 10) {
  730 + len -= 10;
732 731 result = Curl_blockread_all(conn, sock, (char *)&socksreq[10],
733   - packetsize, &actualread);
734   - if((result != CURLE_OK) || (actualread != packetsize)) {
  732 + len, &actualread);
  733 + if((result != CURLE_OK) || (len != actualread)) {
735 734 failf(data, "Failed to receive SOCKS5 connect request ack.");
736 735 return CURLE_COULDNT_CONNECT;
737 736 }

0 comments on commit 07593b2

Please sign in to comment.
Something went wrong with that request. Please try again.