wolfcrypt/src/evp_pk.c: fix benign nullPointer in d2i_make_pkey() reported by cppcheck-2.20.0.

This commit is contained in:
Daniel Pouzzner
2026-03-09 10:58:36 -05:00
parent b3f08f33b8
commit aa4b84f9a2
+11 -6
View File
@@ -67,14 +67,19 @@ static int d2i_make_pkey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
/* Set the size and allocate memory for key data to be copied into. */
pkey->pkey_sz = (int)memSz;
pkey->pkey.ptr = (char*)XMALLOC((size_t)memSz, NULL,
priv ? DYNAMIC_TYPE_PRIVATE_KEY : DYNAMIC_TYPE_PUBLIC_KEY);
if (pkey->pkey.ptr == NULL) {
ret = 0;
if (memSz > 0) {
pkey->pkey.ptr = (char*)XMALLOC((size_t)memSz, NULL,
priv ? DYNAMIC_TYPE_PRIVATE_KEY : DYNAMIC_TYPE_PUBLIC_KEY);
if (pkey->pkey.ptr == NULL) {
ret = 0;
}
if (ret == 1) {
/* Copy in key data. */
XMEMCPY(pkey->pkey.ptr, mem, memSz);
}
}
if (ret == 1) {
/* Copy in key data, set key type passed in and return object. */
XMEMCPY(pkey->pkey.ptr, mem, memSz);
/* Set key type passed in and return object. */
pkey->type = type;
*out = pkey;
}