0
0
mirror of https://github.com/darkk/redsocks.git synced 2025-08-30 13:45:30 +00:00

Fix memory leak in Basic http-auth

This commit is contained in:
Leonid Evdokimov 2016-04-12 00:04:21 +03:00
parent aa6c7500aa
commit f3ef436c8e

View File

@ -32,15 +32,15 @@ char* basic_authentication_encode(const char *user, const char *passwd)
{ {
/* prepare the user:pass key pair */ /* prepare the user:pass key pair */
int pair_len = strlen(user) + 1 + strlen(passwd); int pair_len = strlen(user) + 1 + strlen(passwd);
char *pair_ptr = calloc(pair_len + 1, 1); char pair[pair_len + 1];
sprintf(pair_ptr, "%s:%s", user, passwd); sprintf(pair, "%s:%s", user, passwd);
/* calculate the final string length */ /* calculate the final string length */
int basic_len = BASE64_SIZE(pair_len); int basic_len = BASE64_SIZE(pair_len);
char *basic_ptr = calloc(basic_len + 1, 1); char *basic_ptr = calloc(basic_len + 1, 1);
if (!base64_encode(basic_ptr, basic_len, (const uint8_t*)pair_ptr, pair_len)) if (!base64_encode(basic_ptr, basic_len, (const uint8_t*)pair, pair_len))
return NULL; return NULL;
return basic_ptr; return basic_ptr;