check the return of OPENSSL_sk_new_null
authorxkernel <xkernel.wang@foxmail.com>
Tue, 8 Mar 2022 11:48:54 +0000 (19:48 +0800)
committerMatt Caswell <matt@openssl.org>
Thu, 10 Mar 2022 14:28:06 +0000 (14:28 +0000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Patrick Steuer <patrick.steuer@de.ibm.com>
(Merged from https://github.com/openssl/openssl/pull/17836)

crypto/encode_decode/encoder_pkey.c

index ba29da6385e13fe867c15bd4a15988ac30da80e7..74765a58eadd2c51eb80dd05803dea769582f239 100644 (file)
@@ -254,6 +254,11 @@ static int ossl_encoder_ctx_setup_for_pkey(OSSL_ENCODER_CTX *ctx,
          * First, collect the keymgmt names, then the encoders that match.
          */
         keymgmt_data.names = sk_OPENSSL_CSTRING_new_null();
+        if (keymgmt_data.names == NULL) {
+            ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_MALLOC_FAILURE);
+            goto err;
+        }
+
         keymgmt_data.error_occurred = 0;
         EVP_KEYMGMT_names_do_all(pkey->keymgmt, collect_name, &keymgmt_data);
         if (keymgmt_data.error_occurred) {