From c9def5990e00ef16661707054f871c019291a094 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Mon, 8 Aug 2022 18:56:09 +0300 Subject: [PATCH] [core, mod_sofia] add some extra checks when creating the digest. --- src/mod/endpoints/mod_sofia/sofia_reg.c | 9 +++++---- src/switch_utils.c | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index a07d47b758..42c792c08b 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -2943,23 +2943,24 @@ sofia_auth_algs_t sofia_alg_str2id(char *algorithm, switch_bool_t permissive) switch_status_t sofia_make_digest(sofia_auth_algs_t use_alg, char **digest, const void *input, unsigned int *outputlen) { + switch_status_t status = SWITCH_STATUS_FALSE; switch (use_alg) { case ALG_MD5: - switch_digest_string("md5", digest, input, strlen((char *)input), outputlen); + status = switch_digest_string("md5", digest, input, strlen((char *)input), outputlen); break; case ALG_SHA256: - switch_digest_string("sha256", digest, input, strlen((char *)input), outputlen); + status = switch_digest_string("sha256", digest, input, strlen((char *)input), outputlen); break; #if OPENSSL_VERSION_NUMBER >= 0x10101000L case ALG_SHA512: - switch_digest_string("sha512-256", digest, input, strlen((char *)input), outputlen); + status = switch_digest_string("sha512-256", digest, input, strlen((char *)input), outputlen); break; #endif default: return SWITCH_STATUS_FALSE; } - return SWITCH_STATUS_SUCCESS; + return status; } auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile, diff --git a/src/switch_utils.c b/src/switch_utils.c index d869ddfda4..1a93411489 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -4640,6 +4640,10 @@ SWITCH_DECLARE(switch_status_t) switch_digest_string(const char *digest_name, ch } (*digest_str)[i] = '\0'; + } else { + switch_safe_free(digest); + *outputlen = 0; + return SWITCH_STATUS_FALSE; } }