mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-07-11 14:20:48 +02:00
wolfcrypt/src/evp_pk.c: fix benign nullPointer in d2i_make_pkey() reported by cppcheck-2.20.0.
This commit is contained in:
+11
-6
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user