Fix memory leak in EVP_PKEY_get1_encoded_public_key.
authorslontis <shane.lontis@oracle.com>
Thu, 7 Jul 2022 05:03:08 +0000 (15:03 +1000)
committerHugo Landau <hlandau@openssl.org>
Tue, 12 Jul 2022 06:37:36 +0000 (07:37 +0100)
commit4e9a4997c540e64647d4e1708a1dbda51fb59a68
tree0f4d2de6aab0ad8b051c950be6c21aef2b2fc26d
parent243465fd556837402bff52b7bf3d59420b68a02e
Fix memory leak in EVP_PKEY_get1_encoded_public_key.

Occurs if a failure happens after the malloc call in the second call to
EVP_PKEY_get_octet_string_param().

Detected by PR #18355

Some calling code assumes that nothing is allocated in the returned
pointer if there was a failure. Other calling code always trys freeing.
The third case is in ecdh_cms_encrypt() where it does not check the
return value. I am assuming this change is ok since the legacy path in
EVP_PKEY_get1_encoded_public_key() also does not return the pointer on
failure.

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18739)
crypto/evp/p_lib.c