Stop raising ERR_R_MALLOC_FAILURE in most places
authorRichard Levitte <levitte@openssl.org>
Thu, 29 Sep 2022 11:57:34 +0000 (13:57 +0200)
committerRichard Levitte <levitte@openssl.org>
Wed, 5 Oct 2022 12:02:03 +0000 (14:02 +0200)
commite077455e9e57ed4ee4676996b4a9aa11df6327a6
treeedcb7412024f95fbc97c2c7a780f78ad05d586e3
parent9167a47f78159b0578bc032401ab1d66e14eecdb
Stop raising ERR_R_MALLOC_FAILURE in most places

Since OPENSSL_malloc() and friends report ERR_R_MALLOC_FAILURE, and
at least handle the file name and line number they are called from,
there's no need to report ERR_R_MALLOC_FAILURE where they are called
directly, or when SSLfatal() and RLAYERfatal() is used, the reason
`ERR_R_MALLOC_FAILURE` is changed to `ERR_R_CRYPTO_LIB`.

There were a number of places where `ERR_R_MALLOC_FAILURE` was reported
even though it was a function from a different sub-system that was
called.  Those places are changed to report ERR_R_{lib}_LIB, where
{lib} is the name of that sub-system.
Some of them are tricky to get right, as we have a lot of functions
that belong in the ASN1 sub-system, and all the `sk_` calls or from
the CRYPTO sub-system.

Some extra adaptation was necessary where there were custom OPENSSL_malloc()
wrappers, and some bugs are fixed alongside these changes.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Hugo Landau <hlandau@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19301)
380 files changed:
crypto/asn1/a_bitstr.c
crypto/asn1/a_d2i_fp.c
crypto/asn1/a_digest.c
crypto/asn1/a_dup.c
crypto/asn1/a_i2d_fp.c
crypto/asn1/a_int.c
crypto/asn1/a_mbstr.c
crypto/asn1/a_object.c
crypto/asn1/a_sign.c
crypto/asn1/a_strex.c
crypto/asn1/a_strnid.c
crypto/asn1/a_time.c
crypto/asn1/a_verify.c
crypto/asn1/ameth_lib.c
crypto/asn1/asn1_gen.c
crypto/asn1/asn1_lib.c
crypto/asn1/asn_mime.c
crypto/asn1/asn_moid.c
crypto/asn1/asn_mstbl.c
crypto/asn1/asn_pack.c
crypto/asn1/bio_asn1.c
crypto/asn1/bio_ndef.c
crypto/asn1/f_int.c
crypto/asn1/f_string.c
crypto/asn1/p5_pbe.c
crypto/asn1/p5_pbev2.c
crypto/asn1/p5_scrypt.c
crypto/asn1/tasn_dec.c
crypto/asn1/tasn_enc.c
crypto/asn1/tasn_new.c
crypto/asn1/tasn_prn.c
crypto/asn1/tasn_scn.c
crypto/asn1/tasn_utl.c
crypto/asn1/x_info.c
crypto/asn1/x_int64.c
crypto/asn1/x_pkey.c
crypto/async/arch/async_posix.c
crypto/async/async.c
crypto/async/async_wait.c
crypto/bio/bf_buff.c
crypto/bio/bf_lbuf.c
crypto/bio/bf_nbio.c
crypto/bio/bio_addr.c
crypto/bio/bio_lib.c
crypto/bio/bio_meth.c
crypto/bio/bio_print.c
crypto/bio/bio_sock.c
crypto/bio/bss_acpt.c
crypto/bio/bss_bio.c
crypto/bio/bss_conn.c
crypto/bio/bss_dgram.c
crypto/bio/bss_dgram_pair.c
crypto/bio/bss_log.c
crypto/bio/bss_mem.c
crypto/bn/bn_blind.c
crypto/bn/bn_conv.c
crypto/bn/bn_ctx.c
crypto/bn/bn_gcd.c
crypto/bn/bn_gf2m.c
crypto/bn/bn_intern.c
crypto/bn/bn_lib.c
crypto/bn/bn_mod.c
crypto/bn/bn_mont.c
crypto/bn/bn_prime.c
crypto/bn/bn_rand.c
crypto/bn/bn_recp.c
crypto/buffer/buffer.c
crypto/cmac/cmac.c
crypto/cmp/cmp_ctx.c
crypto/cmp/cmp_msg.c
crypto/cms/cms_dd.c
crypto/cms/cms_enc.c
crypto/cms/cms_env.c
crypto/cms/cms_ess.c
crypto/cms/cms_io.c
crypto/cms/cms_lib.c
crypto/cms/cms_pwri.c
crypto/cms/cms_sd.c
crypto/cms/cms_smime.c
crypto/comp/c_zlib.c
crypto/comp/comp_lib.c
crypto/conf/conf_def.c
crypto/conf/conf_lib.c
crypto/conf/conf_mod.c
crypto/core_algorithm.c
crypto/ct/ct_b64.c
crypto/ct/ct_log.c
crypto/ct/ct_oct.c
crypto/ct/ct_policy.c
crypto/ct/ct_sct.c
crypto/ct/ct_sct_ctx.c
crypto/dh/dh_ameth.c
crypto/dh/dh_err.c
crypto/dh/dh_key.c
crypto/dh/dh_lib.c
crypto/dh/dh_meth.c
crypto/dh/dh_pmeth.c
crypto/dsa/dsa_ameth.c
crypto/dsa/dsa_backend.c
crypto/dsa/dsa_lib.c
crypto/dsa/dsa_meth.c
crypto/dsa/dsa_sign.c
crypto/dso/dso_dl.c
crypto/dso/dso_dlfcn.c
crypto/dso/dso_lib.c
crypto/dso/dso_vms.c
crypto/dso/dso_win32.c
crypto/ec/ec2_smpl.c
crypto/ec/ec_ameth.c
crypto/ec/ec_asn1.c
crypto/ec/ec_backend.c
crypto/ec/ec_check.c
crypto/ec/ec_curve.c
crypto/ec/ec_deprecated.c
crypto/ec/ec_key.c
crypto/ec/ec_kmeth.c
crypto/ec/ec_lib.c
crypto/ec/ec_mult.c
crypto/ec/ec_oct.c
crypto/ec/ec_pmeth.c
crypto/ec/ecdh_ossl.c
crypto/ec/ecdsa_ossl.c
crypto/ec/eck_prn.c
crypto/ec/ecp_nistp224.c
crypto/ec/ecp_nistp256.c
crypto/ec/ecp_nistp521.c
crypto/ec/ecp_nistz256.c
crypto/ec/ecp_s390x_nistp.c
crypto/ec/ecp_smpl.c
crypto/ec/ecx_backend.c
crypto/ec/ecx_key.c
crypto/ec/ecx_meth.c
crypto/encode_decode/decoder_lib.c
crypto/encode_decode/decoder_meth.c
crypto/encode_decode/decoder_pkey.c
crypto/encode_decode/encoder_lib.c
crypto/encode_decode/encoder_meth.c
crypto/encode_decode/encoder_pkey.c
crypto/engine/eng_dyn.c
crypto/engine/eng_init.c
crypto/engine/eng_lib.c
crypto/engine/eng_list.c
crypto/engine/eng_openssl.c
crypto/engine/tb_asnmth.c
crypto/err/openssl.txt
crypto/ess/ess_lib.c
crypto/evp/asymcipher.c
crypto/evp/bio_b64.c
crypto/evp/bio_enc.c
crypto/evp/bio_ok.c
crypto/evp/ctrl_params_translate.c
crypto/evp/digest.c
crypto/evp/e_aes.c
crypto/evp/e_aria.c
crypto/evp/evp_enc.c
crypto/evp/evp_fetch.c
crypto/evp/evp_pbe.c
crypto/evp/evp_pkey.c
crypto/evp/evp_rand.c
crypto/evp/exchange.c
crypto/evp/kdf_lib.c
crypto/evp/kdf_meth.c
crypto/evp/kem.c
crypto/evp/keymgmt_lib.c
crypto/evp/keymgmt_meth.c
crypto/evp/mac_lib.c
crypto/evp/mac_meth.c
crypto/evp/p_lib.c
crypto/evp/p_open.c
crypto/evp/p_seal.c
crypto/evp/p_sign.c
crypto/evp/p_verify.c
crypto/evp/pmeth_gn.c
crypto/evp/pmeth_lib.c
crypto/evp/signature.c
crypto/ex_data.c
crypto/init.c
crypto/lhash/lhash.c
crypto/modes/ocb128.c
crypto/o_fopen.c
crypto/o_str.c
crypto/objects/o_names.c
crypto/objects/obj_dat.c
crypto/objects/obj_lib.c
crypto/objects/obj_xref.c
crypto/ocsp/ocsp_vfy.c
crypto/ocsp/v3_ocsp.c
crypto/packet.c
crypto/param_build.c
crypto/params.c
crypto/params_dup.c
crypto/params_from_text.c
crypto/passphrase.c
crypto/pem/pem_info.c
crypto/pem/pem_lib.c
crypto/pem/pem_sign.c
crypto/pem/pvkfmt.c
crypto/pkcs12/p12_add.c
crypto/pkcs12/p12_decr.c
crypto/pkcs12/p12_init.c
crypto/pkcs12/p12_key.c
crypto/pkcs12/p12_kiss.c
crypto/pkcs12/p12_mutl.c
crypto/pkcs12/p12_p8e.c
crypto/pkcs12/p12_sbag.c
crypto/pkcs12/p12_utl.c
crypto/pkcs7/pk7_asn1.c
crypto/pkcs7/pk7_attr.c
crypto/pkcs7/pk7_doit.c
crypto/pkcs7/pk7_lib.c
crypto/pkcs7/pk7_smime.c
crypto/provider.c
crypto/provider_conf.c
crypto/provider_core.c
crypto/rand/prov_seed.c
crypto/rand/rand_lib.c
crypto/rand/rand_pool.c
crypto/rsa/rsa_ameth.c
crypto/rsa/rsa_backend.c
crypto/rsa/rsa_chk.c
crypto/rsa/rsa_crpt.c
crypto/rsa/rsa_lib.c
crypto/rsa/rsa_meth.c
crypto/rsa/rsa_mp.c
crypto/rsa/rsa_oaep.c
crypto/rsa/rsa_ossl.c
crypto/rsa/rsa_pk1.c
crypto/rsa/rsa_pmeth.c
crypto/rsa/rsa_pss.c
crypto/rsa/rsa_saos.c
crypto/rsa/rsa_sign.c
crypto/sm2/sm2_crypt.c
crypto/sm2/sm2_sign.c
crypto/srp/srp_vfy.c
crypto/stack/stack.c
crypto/store/store_lib.c
crypto/store/store_register.c
crypto/ts/ts_req_utils.c
crypto/ts/ts_rsp_sign.c
crypto/ts/ts_rsp_utils.c
crypto/ts/ts_rsp_verify.c
crypto/ts/ts_verify_ctx.c
crypto/ui/ui_lib.c
crypto/x509/by_dir.c
crypto/x509/by_file.c
crypto/x509/pcy_cache.c
crypto/x509/pcy_data.c
crypto/x509/pcy_node.c
crypto/x509/pcy_tree.c
crypto/x509/v3_addr.c
crypto/x509/v3_akid.c
crypto/x509/v3_asid.c
crypto/x509/v3_bcons.c
crypto/x509/v3_bitst.c
crypto/x509/v3_conf.c
crypto/x509/v3_cpols.c
crypto/x509/v3_crld.c
crypto/x509/v3_extku.c
crypto/x509/v3_ia5.c
crypto/x509/v3_info.c
crypto/x509/v3_ist.c
crypto/x509/v3_lib.c
crypto/x509/v3_ncons.c
crypto/x509/v3_pci.c
crypto/x509/v3_pcons.c
crypto/x509/v3_pmaps.c
crypto/x509/v3_purp.c
crypto/x509/v3_san.c
crypto/x509/v3_skid.c
crypto/x509/v3_sxnet.c
crypto/x509/v3_tlsf.c
crypto/x509/v3_utf8.c
crypto/x509/v3_utl.c
crypto/x509/x509_att.c
crypto/x509/x509_cmp.c
crypto/x509/x509_lu.c
crypto/x509/x509_meth.c
crypto/x509/x509_obj.c
crypto/x509/x509_r2x.c
crypto/x509/x509_req.c
crypto/x509/x509_trust.c
crypto/x509/x509_v3.c
crypto/x509/x509_vfy.c
crypto/x509/x509_vpm.c
crypto/x509/x509name.c
crypto/x509/x509spki.c
crypto/x509/x_crl.c
crypto/x509/x_name.c
crypto/x509/x_pubkey.c
crypto/x509/x_req.c
crypto/x509/x_x509.c
engines/e_capi.c
engines/e_dasync.c
engines/e_loader_attic.c
include/crypto/dherr.h
include/openssl/dherr.h
include/openssl/err.h.in
providers/common/provider_util.c
providers/implementations/asymciphers/rsa_enc.c
providers/implementations/ciphers/cipher_aes.c
providers/implementations/ciphers/cipher_aes_gcm_siv.c
providers/implementations/ciphers/cipher_aes_ocb.c
providers/implementations/ciphers/cipher_aes_siv.c
providers/implementations/ciphers/cipher_aes_xts.c
providers/implementations/ciphers/cipher_aria.c
providers/implementations/ciphers/cipher_blowfish.c
providers/implementations/ciphers/cipher_camellia.c
providers/implementations/ciphers/cipher_cast5.c
providers/implementations/ciphers/cipher_des.c
providers/implementations/ciphers/cipher_idea.c
providers/implementations/ciphers/cipher_rc2.c
providers/implementations/ciphers/cipher_rc4.c
providers/implementations/ciphers/cipher_rc5.c
providers/implementations/ciphers/cipher_seed.c
providers/implementations/ciphers/cipher_sm4.c
providers/implementations/ciphers/cipher_tdes_common.c
providers/implementations/encode_decode/decode_msblob2key.c
providers/implementations/encode_decode/encode_key2any.c
providers/implementations/encode_decode/encode_key2text.c
providers/implementations/exchange/dh_exch.c
providers/implementations/exchange/ecdh_exch.c
providers/implementations/exchange/ecx_exch.c
providers/implementations/kdfs/hkdf.c
providers/implementations/kdfs/kbkdf.c
providers/implementations/kdfs/krb5kdf.c
providers/implementations/kdfs/pbkdf1.c
providers/implementations/kdfs/pbkdf2.c
providers/implementations/kdfs/pkcs12kdf.c
providers/implementations/kdfs/pvkkdf.c
providers/implementations/kdfs/scrypt.c
providers/implementations/kdfs/sshkdf.c
providers/implementations/kdfs/sskdf.c
providers/implementations/kdfs/tls1_prf.c
providers/implementations/kdfs/x942kdf.c
providers/implementations/keymgmt/ec_kmgmt.c
providers/implementations/keymgmt/ecx_kmgmt.c
providers/implementations/keymgmt/mac_legacy_kmgmt.c
providers/implementations/macs/kmac_prov.c
providers/implementations/rands/drbg.c
providers/implementations/rands/drbg_ctr.c
providers/implementations/rands/drbg_hash.c
providers/implementations/rands/drbg_hmac.c
providers/implementations/rands/seed_src.c
providers/implementations/signature/dsa_sig.c
providers/implementations/signature/ecdsa_sig.c
providers/implementations/signature/eddsa_sig.c
providers/implementations/signature/mac_legacy_sig.c
providers/implementations/signature/rsa_sig.c
providers/implementations/signature/sm2_sig.c
providers/implementations/storemgmt/file_store.c
providers/implementations/storemgmt/file_store_any2obj.c
providers/implementations/storemgmt/winstore_store.c
ssl/bio_ssl.c
ssl/d1_lib.c
ssl/pqueue.c
ssl/priority_queue.c
ssl/quic/quic_record_rx_wrap.c
ssl/record/methods/dtls_meth.c
ssl/record/methods/tls1_meth.c
ssl/record/methods/tls_common.c
ssl/record/rec_layer_d1.c
ssl/record/ssl3_buffer.c
ssl/s3_enc.c
ssl/s3_lib.c
ssl/ssl_cert.c
ssl/ssl_ciph.c
ssl/ssl_lib.c
ssl/ssl_rsa.c
ssl/ssl_sess.c
ssl/statem/extensions.c
ssl/statem/extensions_clnt.c
ssl/statem/extensions_srvr.c
ssl/statem/statem_clnt.c
ssl/statem/statem_dtls.c
ssl/statem/statem_lib.c
ssl/statem/statem_srvr.c
ssl/t1_enc.c
ssl/t1_lib.c
ssl/tls13_enc.c
ssl/tls_srp.c