[telepathy-gabble/master] socks5: accept CONNECT reply which doesn't contain a valid domain

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Apr 3 09:26:02 PDT 2009


This is needed to interop with Pidgin
---
 src/bytestream-socks5.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/bytestream-socks5.c b/src/bytestream-socks5.c
index 6e358df..90f829e 100644
--- a/src/bytestream-socks5.c
+++ b/src/bytestream-socks5.c
@@ -104,7 +104,8 @@ typedef enum _Socks5State Socks5State;
 
 #define SHA1_LENGTH 40
 #define SOCKS5_CONNECT_LENGTH (7 + SHA1_LENGTH)
-#define SOCKS5_CONNECT_REPLY_LENGTH (7 + SHA1_LENGTH)
+/* VER + CMD/REP + RSV + ATYP + DOMAIN_LEN + PORT (2) */
+#define SOCKS5_MIN_LENGTH 7
 
 struct _Streamhost
 {
@@ -714,18 +715,20 @@ socks5_handle_received_data (GabbleBytestreamSocks5 *self,
 
       case SOCKS5_STATE_CONNECT_REQUESTED:
         /* We sent a CONNECT request and are awaiting for the response */
-        if (string->len < SOCKS5_CONNECT_REPLY_LENGTH)
+        if (string->len < SOCKS5_MIN_LENGTH)
           return 0;
 
         domain_len = (guint8) string->str[4];
+        if ((guint8) string->len < SOCKS5_MIN_LENGTH + domain_len)
+          /* We didn't receive the full packet yet */
+          return 0;
 
         if (string->str[0] != SOCKS5_VERSION ||
             string->str[1] != SOCKS5_STATUS_OK ||
             string->str[2] != SOCKS5_RESERVED ||
             string->str[3] != SOCKS5_ATYP_DOMAIN ||
-            string->str[4] != SHA1_LENGTH ||
-            string->str[45] != 0 || /* first half of the port number */
-            string->str[46] != 0) /* second half of the port number */
+            string->str[5 + domain_len] != 0 || /* first half of the port number */
+            string->str[6 + domain_len] != 0) /* second half of the port number */
           {
             DEBUG ("Connection refused");
 
@@ -774,7 +777,7 @@ socks5_handle_received_data (GabbleBytestreamSocks5 *self,
             gibber_transport_block_receiving (priv->transport, TRUE);
           }
 
-        return SOCKS5_CONNECT_REPLY_LENGTH;
+        return SOCKS5_MIN_LENGTH + domain_len;
 
       case SOCKS5_STATE_AWAITING_AUTH_REQUEST:
         /* A client connected to us and we are awaiting for the authorization
-- 
1.5.6.5




More information about the telepathy-commits mailing list