current gateway.c,1.96,1.97

Fabian Keil <[email protected]> Tue, 25 Oct 2016 10:43:02 +0000
Newsgroups gmane.comp.web.privoxy.cvs
Message-ID <[email protected]>
Update of /cvsroot/ijbswa/current
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv16671

Modified Files:
	gateway.c 
Log Message:
socks5_connect(): Properly deal with socks replies that contain IPv6 addresses

Previously parts of the reply were left unread and
later on treated as invalid HTTP response data.

Fixes #904 reported by Danny Goossen who also provided
the initial version of this patch.


Index: gateway.c
===================================================================
RCS file: /cvsroot/ijbswa/current/gateway.c,v
retrieving revision 1.96
retrieving revision 1.97
diff -C2 -d -r1.96 -r1.97
*** gateway.c	16 Jan 2016 12:30:43 -0000	1.96
--- gateway.c	25 Oct 2016 10:43:00 -0000	1.97
***************
*** 936,942 ****
                                  struct client_state *csp)
  {
     int err = 0;
     char cbuf[300];
!    char sbuf[10];
     size_t client_pos = 0;
     int server_size = 0;
--- 936,945 ----
                                  struct client_state *csp)
  {
+ #define SIZE_SOCKS5_REPLY_IPV4 10
+ #define SIZE_SOCKS5_REPLY_IPV6 22
+ #define SOCKS5_REPLY_DIFFERENCE (SIZE_SOCKS5_REPLY_IPV6 - SIZE_SOCKS5_REPLY_IPV4)
     int err = 0;
     char cbuf[300];
!    char sbuf[SIZE_SOCKS5_REPLY_IPV6];
     size_t client_pos = 0;
     int server_size = 0;
***************
*** 1135,1140 ****
     }
  
!    server_size = read_socket(sfd, sbuf, sizeof(sbuf));
!    if (server_size != sizeof(sbuf))
     {
        errstr = "SOCKS5 negotiation read failed";
--- 1138,1143 ----
     }
  
!    server_size = read_socket(sfd, sbuf, SIZE_SOCKS5_REPLY_IPV4);
!    if (server_size != SIZE_SOCKS5_REPLY_IPV4)
     {
        errstr = "SOCKS5 negotiation read failed";
***************
*** 1156,1160 ****
        else
        {
!          return(sfd);
        }
     }
--- 1159,1180 ----
        else
        {
!          if (sbuf[3] == '\x04')
!          {
!             /*
!              * The address field contains an IPv6 address
!              * which means we didn't get the whole reply
!              * yet. Read and discard the rest of it to make
!              * sure it isn't treated as HTTP data later on.
!              */
!             server_size = read_socket(sfd, sbuf, SOCKS5_REPLY_DIFFERENCE);
!             if (server_size != SOCKS5_REPLY_DIFFERENCE)
!             {
!                errstr = "SOCKS5 negotiation read failed (IPv6 address)";
!             }
!          }
!          if (errstr == NULL)
!          {
!             return(sfd);
!          }
        }
     }


------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive. 
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik