From 3a58bcc0a98d4bd474d1d11041465854358f8b48 Mon Sep 17 00:00:00 2001 From: Norman Ashley Date: Sat, 31 Aug 2024 15:06:39 -0400 Subject: [PATCH] Fix Dereference before null check. --- oqsprov/oqs_kem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/oqsprov/oqs_kem.c b/oqsprov/oqs_kem.c index adc11f46..aba8c073 100644 --- a/oqsprov/oqs_kem.c +++ b/oqsprov/oqs_kem.c @@ -103,13 +103,15 @@ static int oqs_qs_kem_encaps_keyslot(void *vpkemctx, unsigned char *out, size_t *outlen, unsigned char *secret, size_t *secretlen, int keyslot) { const PROV_OQSKEM_CTX *pkemctx = (PROV_OQSKEM_CTX *)vpkemctx; - const OQS_KEM *kem_ctx = pkemctx->kem->oqsx_provider_ctx.oqsx_qs_ctx.kem; + const OQS_KEM *kem_ctx = NULL; OQS_KEM_PRINTF("OQS KEM provider called: encaps\n"); - if (pkemctx->kem == NULL) { + if (!pkemctx->kem || !pkemctx->kem->oqsx_provider_ctx) { OQS_KEM_PRINTF("OQS Warning: OQS_KEM not initialized\n"); return -1; } + + kem_ctx = pkemctx->kem->oqsx_provider_ctx.oqsx_qs_ctx.kem; if (pkemctx->kem->comp_pubkey == NULL || pkemctx->kem->comp_pubkey[keyslot] == NULL) { OQS_KEM_PRINTF("OQS Warning: public key is NULL\n");