Skip to content

Commit

Permalink
fix size_t and improve ENOMEM err
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Apr 21, 2024
1 parent f1a2804 commit 07ecdff
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/sip/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,29 @@ static int mkdigest(struct mbuf **digestp, const struct realm *realm,
const char *met, const char *uri, uint64_t cnonce)
{
struct mbuf *digest;
uint8_t *ha1 = NULL, *ha2 = NULL;
digest_printf_h *digest_printf;
int err;

bool use_sha256 = str_casecmp(realm->algorithm, "sha-256") == 0;
int h_size = use_sha256 ? SHA256_DIGEST_SIZE : MD5_SIZE;
size_t h_size = use_sha256 ? SHA256_DIGEST_SIZE : MD5_SIZE;

digest = mbuf_alloc(h_size);
if (!digest)
return ENOMEM;

mbuf_set_end(digest, h_size);

uint8_t *ha1 = mem_alloc(h_size, NULL);
if (!ha1)
return ENOMEM;
ha1 = mem_zalloc(h_size, NULL);
if (!ha1) {
err = ENOMEM;
goto out;
}

uint8_t *ha2 = mem_alloc(h_size, NULL);
ha2 = mem_zalloc(h_size, NULL);
if (!ha2) {
mem_deref(ha1);
return ENOMEM;
err = ENOMEM;
goto out;
}

if (use_sha256)
Expand Down Expand Up @@ -141,7 +144,9 @@ static int mkdigest(struct mbuf **digestp, const struct realm *realm,
mem_deref(ha1);
mem_deref(ha2);

if (!err)
if (err)
mem_deref(digest);
else
*digestp = digest;

return err;
Expand Down

0 comments on commit 07ecdff

Please sign in to comment.