]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Use stricter snprintf() formatting in socks_username_password_auth() (v3)
authorDavid Sommerseth <dazo@users.sourceforge.net>
Mon, 15 Nov 2010 20:44:59 +0000 (21:44 +0100)
committerDavid Sommerseth <dazo@users.sourceforge.net>
Thu, 18 Nov 2010 17:54:49 +0000 (18:54 +0100)
commit fc1fa9ffc7e3356458ec3 added a new function which needs to have a
stricter string formatting.  This was detected due to a compiler warning.

This patch makes sure that the length of username and password is not longer
than 255 bytes.  It also adds extra checks to avoid NULL pointer issues with
strlen() on these two parameters.

Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
socks.c

diff --git a/socks.c b/socks.c
index 58b3648bf589c587ab1e5764196a59cd7b64780a..c7c0473c7a8adc9890d90d6bea60b0d956d29ecf 100644 (file)
--- a/socks.c
+++ b/socks.c
@@ -112,10 +112,17 @@ socks_username_password_auth (struct socks_proxy_info *p,
   ssize_t size;
 
   creds.defined = 0;
-
   get_user_pass (&creds, p->authfile, UP_TYPE_SOCKS, GET_USER_PASS_MANAGEMENT);
-  snprintf (to_send, sizeof (to_send), "\x01%c%s%c%s", strlen(creds.username),
-            creds.username, strlen(creds.password), creds.password);
+
+  if( !creds.username || (strlen(creds.username) > 255)
+      || !creds.password || (strlen(creds.password) > 255) ) {
+          msg (M_NONFATAL,
+               "SOCKS username and/or password exceeds 255 characters.  "
+               "Authentication not possible.");
+          return false;
+  }
+  snprintf (to_send, sizeof (to_send), "\x01%c%s%c%s", (int) strlen(creds.username),
+            creds.username, (int) strlen(creds.password), creds.password);
   size = send (sd, to_send, strlen(to_send), MSG_NOSIGNAL);
 
   if (size != strlen (to_send))