Skip to content

Commit

Permalink
httpauth: use a stack array for the hash instead of heap
Browse files Browse the repository at this point in the history
  • Loading branch information
cHuberCoffee committed Aug 30, 2023
1 parent af14517 commit 68c2ee3
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/httpauth/digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,20 +434,13 @@ static int generate_nonce(char **pnonce, const time_t ts,
{
struct mbuf *mb = NULL;
char *nonce = NULL;
uint8_t *hash = NULL;
size_t hashlen = SHA256_DIGEST_LENGTH;
uint8_t hash [SHA256_DIGEST_LENGTH];
int err = 0;

mb = mbuf_alloc(32);
if (!mb)
return ENOMEM;

hash = mem_zalloc(hashlen, NULL);
if (!hash) {
err = ENOMEM;
goto out;
}

if (str_isset(secret))
err = mbuf_printf(mb, "%"PRIu64":%s:%s",
(uint64_t)ts, etag, secret);
Expand All @@ -460,7 +453,7 @@ static int generate_nonce(char **pnonce, const time_t ts,
sha256(mb->buf, mb->end, hash);
mbuf_rewind(mb);

err = mbuf_printf(mb, "%w%016"PRIx64"", hash, hashlen, (uint64_t)ts);
err = mbuf_printf(mb, "%w%016"PRIx64"", hash, sizeof(hash), (uint64_t)ts);
if (err)
goto out;

Expand All @@ -474,7 +467,6 @@ static int generate_nonce(char **pnonce, const time_t ts,
*pnonce = nonce;

mem_deref(mb);
mem_deref(hash);

return err;
}
Expand Down

0 comments on commit 68c2ee3

Please sign in to comment.