Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ae8755

Browse files
esyrnhorman
authored andcommitted
kmac_prov.c.in: avoid resource leak on kmac_new_decoder fail in kmac_fetch_new
kctx was not freed in a case of kmac_new_decoder failure; consolidate all the error paths under the "err:" label and jump to it on kmac_new_decoder() returning 0. Fixes: d5efc85 "kmac: avoid using ossl_prov_digest_load_from_params()" Resolves: openssl/project#1419 Resolves: https://scan5.scan.coverity.com/#/project-view/65248/10222?selectedIssue=1453634 Signed-off-by: Eugene Syromiatnikov <[email protected]> Reviewed-by: Saša Nedvědický <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tom Cosgrove <[email protected]> Reviewed-by: Neil Horman <[email protected]> (Merged from #28516)
1 parent 6c30466 commit 3ae8755

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

providers/implementations/macs/kmac_prov.c.in

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,23 @@ static void *kmac_fetch_new(void *provctx, const OSSL_PARAM *params)
203203
struct kmac_new_st p;
204204
int md_size;
205205

206-
if (kctx == NULL || !kmac_new_decoder(params, &p))
206+
if (kctx == NULL)
207207
return 0;
208+
if (!kmac_new_decoder(params, &p))
209+
goto err;
208210
if (!ossl_prov_digest_load(&kctx->digest, p.digest, p.propq, p.engine,
209-
PROV_LIBCTX_OF(provctx))) {
210-
kmac_free(kctx);
211-
return 0;
212-
}
211+
PROV_LIBCTX_OF(provctx)))
212+
goto err;
213213

214214
md_size = EVP_MD_get_size(ossl_prov_digest_md(&kctx->digest));
215-
if (md_size <= 0) {
216-
kmac_free(kctx);
217-
return 0;
218-
}
215+
if (md_size <= 0)
216+
goto err;
219217
kctx->out_len = (size_t)md_size;
220218
return kctx;
219+
220+
err:
221+
kmac_free(kctx);
222+
return NULL;
221223
}
222224

223225
static void *kmac128_new(void *provctx)

0 commit comments

Comments
 (0)