From 444db0ad8556ef7ba15c40280b62cd08dc0ed747 Mon Sep 17 00:00:00 2001 From: tb Date: Tue, 10 Jul 2018 20:53:30 +0000 Subject: [PATCH] Now that all *_free() functions are NULL safe, we can generate the freenull test from Symbols.list. Suggested by jsing, discussed with beck and bluhm. --- regress/lib/libcrypto/free/Makefile | 11 +- regress/lib/libcrypto/free/freenull.awk | 60 ++++++ regress/lib/libcrypto/free/freenull.c | 237 --------------------- regress/lib/libcrypto/free/freenull.c.head | 27 +++ regress/lib/libcrypto/free/freenull.c.tail | 27 +++ 5 files changed, 123 insertions(+), 239 deletions(-) create mode 100644 regress/lib/libcrypto/free/freenull.awk delete mode 100644 regress/lib/libcrypto/free/freenull.c create mode 100644 regress/lib/libcrypto/free/freenull.c.head create mode 100644 regress/lib/libcrypto/free/freenull.c.tail diff --git a/regress/lib/libcrypto/free/Makefile b/regress/lib/libcrypto/free/Makefile index cde5cb6702d..dabc06262e4 100644 --- a/regress/lib/libcrypto/free/Makefile +++ b/regress/lib/libcrypto/free/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.1 2017/05/02 04:03:06 beck Exp $ +# $OpenBSD: Makefile,v 1.2 2018/07/10 20:53:30 tb Exp $ TESTS = \ freenull @@ -10,7 +10,14 @@ DPADD= ${LIBCRYPTO} ${LIBSSL} LDFLAGS+= -lcrypto CFLAGS+= -DLIBRESSL_INTERNAL -CLEANFILES+= ${TESTS} +CLEANFILES+= ${TESTS} ${TESTS}.d freenull.c freenull.c.body freenull.c.tmp + +freenull.c: freenull.awk ../../../../lib/libcrypto/Symbols.list + awk -f ${.CURDIR}/freenull.awk \ + < ${BSDSRCDIR}/lib/libcrypto/Symbols.list > freenull.c.body + cat ${.CURDIR}/freenull.c.head freenull.c.body \ + ${.CURDIR}/freenull.c.tail > freenull.c.tmp + mv freenull.c.tmp freenull.c all_tests: ${TESTS} @for test in $>; do \ diff --git a/regress/lib/libcrypto/free/freenull.awk b/regress/lib/libcrypto/free/freenull.awk new file mode 100644 index 00000000000..95719da956c --- /dev/null +++ b/regress/lib/libcrypto/free/freenull.awk @@ -0,0 +1,60 @@ +# $OpenBSD: freenull.awk,v 1.1 2018/07/10 20:53:30 tb Exp $ +# Copyright (c) 2018 Theo Buehler +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# usage: awk -f freenull.awk < Symbols.list > freenull.c.body + +# Skip this function because it calls abort(3). +/^CRYPTO_dbg_free/ { + next +} + +# Skip *_free functions that take more than one or no argument. +/^ASN1_item_ex_free$/ || +/^ASN1_item_free$/ || +/^ASN1_primitive_free$/ || +/^ASN1_template_free$/ || +/^CONF_modules_free$/ || +/^EVP_PKEY_asn1_set_free$/ || +/^OBJ_sigid_free$/ || +/^X509V3_section_free$/ || +/^X509V3_string_free$/ || +/^asn1_enc_free$/ || +/^sk_pop_free$/ { + next +} + +# Skip functions that are prototyped in a .c file. +/^BIO_CONNECT_free$/ || +/^CRYPTO_free$/ || +/^EC_PRIVATEKEY_free$/ || +/^ECPARAMETERS_free$/ || +/^ECPKPARAMETERS_free$/ || +/^NETSCAPE_ENCRYPTED_PKEY_free$/ || +/^NETSCAPE_PKEY_free$/ || +/^X9_62_CHARACTERISTIC_TWO_free$/ || +/^X9_62_PENTANOMIAL_free$/ { + next +} + +/^ENGINE_free$/ { + printf("#ifndef OPENSSL_NO_ENGINE\n") + printf("\tENGINE_free(NULL);\n") + printf("#endif\n") + next +} + +/_free$/ { + printf("\t%s(NULL);\n", $0) +} diff --git a/regress/lib/libcrypto/free/freenull.c b/regress/lib/libcrypto/free/freenull.c deleted file mode 100644 index 2735e7f7599..00000000000 --- a/regress/lib/libcrypto/free/freenull.c +++ /dev/null @@ -1,237 +0,0 @@ -/* $OpenBSD: freenull.c,v 1.13 2018/05/15 07:11:31 tb Exp $ */ -/* - * Copyright (c) 2017 Bob Beck - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include -#include -#include -#include -#include -#ifndef OPENSSL_NO_ENGINE -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -/* Make sure we do the right thing. Add here if you convert ones in tree */ -int -main(int argc, char **argv) -{ - ACCESS_DESCRIPTION_free(NULL); - ASN1_BIT_STRING_free(NULL); - ASN1_BMPSTRING_free(NULL); - ASN1_ENUMERATED_free(NULL); - ASN1_GENERALIZEDTIME_free(NULL); - ASN1_GENERALSTRING_free(NULL); - ASN1_IA5STRING_free(NULL); - ASN1_INTEGER_free(NULL); - ASN1_NULL_free(NULL); - ASN1_OBJECT_free(NULL); - ASN1_OCTET_STRING_free(NULL); - ASN1_PCTX_free(NULL); - ASN1_PRINTABLESTRING_free(NULL); - ASN1_PRINTABLE_free(NULL); - ASN1_STRING_free(NULL); - ASN1_T61STRING_free(NULL); - ASN1_TIME_free(NULL); - ASN1_TYPE_free(NULL); - ASN1_UNIVERSALSTRING_free(NULL); - ASN1_UTCTIME_free(NULL); - ASN1_UTF8STRING_free(NULL); - ASN1_VISIBLESTRING_free(NULL); - AUTHORITY_INFO_ACCESS_free(NULL); - AUTHORITY_KEYID_free(NULL); - BASIC_CONSTRAINTS_free(NULL); - BIO_free(NULL); - BIO_free_all(NULL); - BIO_meth_free(NULL); - BN_BLINDING_free(NULL); - BN_CTX_free(NULL); - BN_GENCB_free(NULL); - BN_MONT_CTX_free(NULL); - BN_RECP_CTX_free(NULL); - BN_clear_free(NULL); - BN_free(NULL); - BUF_MEM_free(NULL); - CERTIFICATEPOLICIES_free(NULL); - CMAC_CTX_free(NULL); - COMP_CTX_free(NULL); - CONF_free(NULL); - CRL_DIST_POINTS_free(NULL); - DH_free(NULL); - DIRECTORYSTRING_free(NULL); - DISPLAYTEXT_free(NULL); - DIST_POINT_NAME_free(NULL); - DIST_POINT_free(NULL); - DSA_SIG_free(NULL); - DSA_free(NULL); - DSA_meth_free(NULL); - DSO_free(NULL); - ECDSA_SIG_free(NULL); - EC_GROUP_clear_free(NULL); - EC_GROUP_free(NULL); - EC_KEY_free(NULL); - EC_POINT_clear_free(NULL); - EC_POINT_free(NULL); - EDIPARTYNAME_free(NULL); -#ifndef OPENSSL_NO_ENGINE - ENGINE_free(NULL); -#endif - ESS_CERT_ID_free(NULL); - ESS_ISSUER_SERIAL_free(NULL); - ESS_SIGNING_CERT_free(NULL); - EVP_CIPHER_CTX_free(NULL); - EVP_MD_CTX_free(NULL); - EVP_PKEY_CTX_free(NULL); - EVP_PKEY_asn1_free(NULL); - EVP_PKEY_free(NULL); - EVP_PKEY_meth_free(NULL); - EXTENDED_KEY_USAGE_free(NULL); - GENERAL_NAMES_free(NULL); - GENERAL_NAME_free(NULL); - GENERAL_SUBTREE_free(NULL); - GOST_CIPHER_PARAMS_free(NULL); - GOST_KEY_free(NULL); - HMAC_CTX_free(NULL); - ISSUING_DIST_POINT_free(NULL); - NAME_CONSTRAINTS_free(NULL); - NCONF_free(NULL); - NCONF_free_data(NULL); - NETSCAPE_CERT_SEQUENCE_free(NULL); - NETSCAPE_SPKAC_free(NULL); - NETSCAPE_SPKI_free(NULL); - NETSCAPE_X509_free(NULL); - NOTICEREF_free(NULL); - OCSP_BASICRESP_free(NULL); - OCSP_CERTID_free(NULL); - OCSP_CERTSTATUS_free(NULL); - OCSP_CRLID_free(NULL); - OCSP_ONEREQ_free(NULL); - OCSP_REQINFO_free(NULL); - OCSP_REQUEST_free(NULL); - OCSP_REQ_CTX_free(NULL); - OCSP_RESPBYTES_free(NULL); - OCSP_RESPDATA_free(NULL); - OCSP_RESPID_free(NULL); - OCSP_RESPONSE_free(NULL); - OCSP_REVOKEDINFO_free(NULL); - OCSP_SERVICELOC_free(NULL); - OCSP_SIGNATURE_free(NULL); - OCSP_SINGLERESP_free(NULL); - OTHERNAME_free(NULL); - PBEPARAM_free(NULL); - PBKDF2PARAM_free(NULL); - PKCS12_BAGS_free(NULL); - PKCS12_MAC_DATA_free(NULL); - PKCS12_SAFEBAG_free(NULL); - PKCS12_free(NULL); - PKCS7_DIGEST_free(NULL); - PKCS7_ENCRYPT_free(NULL); - PKCS7_ENC_CONTENT_free(NULL); - PKCS7_ENVELOPE_free(NULL); - PKCS7_ISSUER_AND_SERIAL_free(NULL); - PKCS7_RECIP_INFO_free(NULL); - PKCS7_SIGNED_free(NULL); - PKCS7_SIGNER_INFO_free(NULL); - PKCS7_SIGN_ENVELOPE_free(NULL); - PKCS7_free(NULL); - PKCS8_PRIV_KEY_INFO_free(NULL); - PKEY_USAGE_PERIOD_free(NULL); - POLICYINFO_free(NULL); - POLICYQUALINFO_free(NULL); - POLICY_CONSTRAINTS_free(NULL); - POLICY_MAPPING_free(NULL); - PROXY_CERT_INFO_EXTENSION_free(NULL); - PROXY_POLICY_free(NULL); - RSA_PSS_PARAMS_free(NULL); - RSA_free(NULL); - RSA_meth_free(NULL); - SXNETID_free(NULL); - SXNET_free(NULL); - TS_ACCURACY_free(NULL); - TS_MSG_IMPRINT_free(NULL); - TS_REQ_ext_free(NULL); - TS_REQ_free(NULL); - TS_RESP_CTX_free(NULL); - TS_RESP_free(NULL); - TS_STATUS_INFO_free(NULL); - TS_TST_INFO_ext_free(NULL); - TS_TST_INFO_free(NULL); - TS_VERIFY_CTX_free(NULL); - TXT_DB_free(NULL); - UI_free(NULL); - USERNOTICE_free(NULL); - X509V3_conf_free(NULL); - X509_ALGOR_free(NULL); - X509_ATTRIBUTE_free(NULL); - X509_CERT_AUX_free(NULL); - X509_CERT_PAIR_free(NULL); - X509_CINF_free(NULL); - X509_CRL_INFO_free(NULL); - X509_CRL_METHOD_free(NULL); - X509_CRL_free(NULL); - X509_EXTENSION_free(NULL); - X509_INFO_free(NULL); - X509_LOOKUP_free(NULL); - X509_NAME_ENTRY_free(NULL); - X509_NAME_free(NULL); - X509_PKEY_free(NULL); - X509_PUBKEY_free(NULL); - X509_REQ_INFO_free(NULL); - X509_REQ_free(NULL); - X509_REVOKED_free(NULL); - X509_SIG_free(NULL); - X509_STORE_CTX_free(NULL); - X509_STORE_free(NULL); - X509_VAL_free(NULL); - X509_VERIFY_PARAM_free(NULL); - X509_email_free(NULL); - X509_free(NULL); - X509_policy_tree_free(NULL); - - lh_FUNCTION_free(NULL); - - sk_ASN1_OBJECT_pop_free(NULL, NULL); - sk_CONF_VALUE_pop_free(NULL, NULL); - sk_GENERAL_NAME_pop_free(NULL, NULL); - sk_OCSP_CERTID_free(NULL); - sk_OPENSSL_STRING_free(NULL); - sk_PKCS12_SAFEBAG_pop_free(NULL, NULL); - sk_PKCS7_pop_free(NULL, NULL); - sk_X509_ATTRIBUTE_free(NULL); - sk_X509_CRL_pop_free(NULL, NULL); - sk_X509_EXTENSION_pop_free(NULL, NULL); - sk_X509_INFO_free(NULL); - sk_X509_INFO_pop_free(NULL, NULL); - sk_X509_NAME_ENTRY_pop_free(NULL, NULL); - sk_X509_free(NULL); - sk_X509_pop_free(NULL, NULL); - - printf("PASS\n"); - - return 0; -} diff --git a/regress/lib/libcrypto/free/freenull.c.head b/regress/lib/libcrypto/free/freenull.c.head new file mode 100644 index 00000000000..b63703d7d21 --- /dev/null +++ b/regress/lib/libcrypto/free/freenull.c.head @@ -0,0 +1,27 @@ +/* freenull.c IS GENERATED BY 'make nulltests' DO NOT EDIT BY HAND */ + +#include +#include +#include +#include +#include +#ifndef OPENSSL_NO_ENGINE +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +int +main(int argc, char **argv) +{ diff --git a/regress/lib/libcrypto/free/freenull.c.tail b/regress/lib/libcrypto/free/freenull.c.tail new file mode 100644 index 00000000000..4300c38d982 --- /dev/null +++ b/regress/lib/libcrypto/free/freenull.c.tail @@ -0,0 +1,27 @@ + + BIO_free_all(NULL); + NCONF_free_data(NULL); + _CONF_free_data(NULL); + + lh_FUNCTION_free(NULL); + + sk_ASN1_OBJECT_pop_free(NULL, NULL); + sk_CONF_VALUE_pop_free(NULL, NULL); + sk_GENERAL_NAME_pop_free(NULL, NULL); + sk_OCSP_CERTID_free(NULL); + sk_OPENSSL_STRING_free(NULL); + sk_PKCS12_SAFEBAG_pop_free(NULL, NULL); + sk_PKCS7_pop_free(NULL, NULL); + sk_X509_ATTRIBUTE_free(NULL); + sk_X509_CRL_pop_free(NULL, NULL); + sk_X509_EXTENSION_pop_free(NULL, NULL); + sk_X509_INFO_free(NULL); + sk_X509_INFO_pop_free(NULL, NULL); + sk_X509_NAME_ENTRY_pop_free(NULL, NULL); + sk_X509_free(NULL); + sk_X509_pop_free(NULL, NULL); + + printf("PASS\n"); + + return 0; +} -- 2.20.1