Skip to content

Commit

Permalink
Fix memory leak in Basic http-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
darkk committed Apr 12, 2016
1 parent aa6c750 commit f3ef436
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions http-auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ char* basic_authentication_encode(const char *user, const char *passwd)
{
/* prepare the user:pass key pair */
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 */
int basic_len = BASE64_SIZE(pair_len);
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 basic_ptr;
Expand Down

0 comments on commit f3ef436

Please sign in to comment.