From 5005cc36d7c9aa51267ac8be626994f4abaa7f87 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 18 Mar 2022 09:11:46 -0400 Subject: [PATCH] TT#14008 handle HMAC() returning error If HMAC() fails, the value of the output string would be left uninitialised. Handle this case. Change-Id: I79fc3d03237ae4a5924e59f749d6818db7bf8ab2 Warned-by: coverity --- daemon/crypto.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/daemon/crypto.c b/daemon/crypto.c index e04dc8bd2..79749a203 100644 --- a/daemon/crypto.c +++ b/daemon/crypto.c @@ -836,8 +836,12 @@ static int hmac_sha1_rtp(struct crypto_context *c, char *out, str *in, uint64_t static int hmac_sha1_rtcp(struct crypto_context *c, char *out, str *in) { unsigned char hmac[20]; - HMAC(EVP_sha1(), c->session_auth_key, c->params.crypto_suite->srtcp_auth_key_len, - (unsigned char *) in->s, in->len, hmac, NULL); + if (!HMAC(EVP_sha1(), c->session_auth_key, c->params.crypto_suite->srtcp_auth_key_len, + (unsigned char *) in->s, in->len, hmac, NULL)) + { + memset(out, 0, c->params.crypto_suite->srtcp_auth_tag); + return 1; + } assert(sizeof(hmac) >= c->params.crypto_suite->srtcp_auth_tag); memcpy(out, hmac, c->params.crypto_suite->srtcp_auth_tag);