From 07ecdff0f448f6fea1639bed33dd1cd2cdb6a08a Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sun, 21 Apr 2024 15:59:51 +0200 Subject: [PATCH] fix size_t and improve ENOMEM err --- src/sip/auth.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/sip/auth.c b/src/sip/auth.c index 0935a9499..cc73a2d5a 100644 --- a/src/sip/auth.c +++ b/src/sip/auth.c @@ -94,11 +94,12 @@ 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) @@ -106,14 +107,16 @@ static int mkdigest(struct mbuf **digestp, const struct realm *realm, 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) @@ -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;