From 1ebebe1d2f9cf8b2baa65b2c8651bf930464ad24 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Mon, 17 Jan 2022 21:36:49 -0500 Subject: [PATCH] lib/hcrypto: RSA_check_key if rsa->n is NULL cannot call RSA_size Avoid a theoretical NULL pointer dereference. Change-Id: Ia7b8671152b5444fd5cfdb3e37fd62e4db68c9c5 --- lib/hcrypto/rsa.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/hcrypto/rsa.c b/lib/hcrypto/rsa.c index 3638677c3..6172b2541 100644 --- a/lib/hcrypto/rsa.c +++ b/lib/hcrypto/rsa.c @@ -272,7 +272,10 @@ RSA_check_key(const RSA *key) * and then decrypt/verify. */ - if ((rsa->d == NULL || rsa->n == NULL) && + if (rsa->n == NULL) + return 0; + + if (rsa->d == NULL && (rsa->p == NULL || rsa->q || rsa->dmp1 == NULL || rsa->dmq1 == NULL || rsa->iqmp == NULL)) return 0;