]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
socks: better buffer size checks for socks4a user and hostname
authorDaniel Stenberg <daniel@haxx.se>
Thu, 12 Oct 2023 22:15:29 +0000 (00:15 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 16 Oct 2023 21:47:08 +0000 (23:47 +0200)
Also limit the proxy user name to 255 bytes, which is the same limit as
in SOCKS5.

Reported-by: sd0 on hackerone
Closes #12139

lib/socks.c

index a7b5ab07e47d0a2140b1d25a87ead02a3f45a5e0..6d6368c3a5978308161ceb43005b715cf44d826c 100644 (file)
@@ -402,8 +402,11 @@ CONNECT_REQ_INIT:
     socksreq[8] = 0; /* ensure empty userid is NUL-terminated */
     if(sx->proxy_user) {
       size_t plen = strlen(sx->proxy_user);
-      if(plen >= (size_t)data->set.buffer_size - 8) {
-        failf(data, "Too long SOCKS proxy user name, can't use");
+      if(plen > 255) {
+        /* there is no real size limit to this field in the protocol, but
+           SOCKS5 limits the proxy user field to 255 bytes and it seems likely
+           that a longer field is either a mistake or malicous input */
+        failf(data, "Too long SOCKS proxy user name");
         return CURLPX_LONG_USER;
       }
       /* copy the proxy name WITH trailing zero */
@@ -426,7 +429,8 @@ CONNECT_REQ_INIT:
         socksreq[7] = 1;
         /* append hostname */
         hostnamelen = strlen(sx->hostname) + 1; /* length including NUL */
-        if(hostnamelen <= 255)
+        if((hostnamelen <= 255) &&
+           (packetsize + hostnamelen < data->set.buffer_size))
           strcpy((char *)socksreq + packetsize, sx->hostname);
         else {
           failf(data, "SOCKS4: too long host name");