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>
| ... | ... |
@@ -112,10 +112,17 @@ socks_username_password_auth (struct socks_proxy_info *p, |
| 112 | 112 |
ssize_t size; |
| 113 | 113 |
|
| 114 | 114 |
creds.defined = 0; |
| 115 |
- |
|
| 116 | 115 |
get_user_pass (&creds, p->authfile, UP_TYPE_SOCKS, GET_USER_PASS_MANAGEMENT); |
| 117 |
- snprintf (to_send, sizeof (to_send), "\x01%c%s%c%s", strlen(creds.username), |
|
| 118 |
- creds.username, strlen(creds.password), creds.password); |
|
| 116 |
+ |
|
| 117 |
+ if( !creds.username || (strlen(creds.username) > 255) |
|
| 118 |
+ || !creds.password || (strlen(creds.password) > 255) ) {
|
|
| 119 |
+ msg (M_NONFATAL, |
|
| 120 |
+ "SOCKS username and/or password exceeds 255 characters. " |
|
| 121 |
+ "Authentication not possible."); |
|
| 122 |
+ return false; |
|
| 123 |
+ } |
|
| 124 |
+ snprintf (to_send, sizeof (to_send), "\x01%c%s%c%s", (int) strlen(creds.username), |
|
| 125 |
+ creds.username, (int) strlen(creds.password), creds.password); |
|
| 119 | 126 |
size = send (sd, to_send, strlen(to_send), MSG_NOSIGNAL); |
| 120 | 127 |
|
| 121 | 128 |
if (size != strlen (to_send)) |