The function print_keyspec in apps/cmp.c previously dereferenced the 'alg' pointer
without checking if it was NULL:
if (paramtype == V_ASN1_UNDEF || alg->parameter == NULL) {
In certain situations, the 'alg' pointer could be NULL, which may result in a null
pointer dereference.
This commit adds an explicit null check for 'alg' before dereferencing 'alg->parameter'
to ensure safe handling:
if (alg == NULL) {
BIO_puts(mem, "Key algorithm: <absent>\n");
break;
}
This prevents potential crashes when print_keyspec is called with a NULL algorithm
pointer, improving the robustness of the CMP application.
Reviewed-by: Frederik Wedel-Heinen <fwh.openssl@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
MergeDate: Thu Feb 19 12:56:01 2026
(Merged from https://github.com/openssl/openssl/pull/30046)
int paramtype;
const void *param;
+ /* NULL check to prevent dereferencing a NULL pointer when print_keyspec is called */
+ if (alg == NULL) {
+ BIO_puts(mem, "Key algorithm: <absent>\n");
+ break;
+ }
+
X509_ALGOR_get0(&oid, ¶mtype, ¶m, alg);
BIO_puts(mem, "Key algorithm: ");
i2a_ASN1_OBJECT(mem, oid);