The branch master has been updated via 51ba9ebd09bfa3569fee935ef7063394820cd333 (commit) via 8c0e76813af6a886f66d3e95b908c6c924d2a6ad (commit) via f6aca23e268799380e4e4193789ed96db1ed57f3 (commit) via 0f17ac26fc552b7f233e8765e6b6a278c9731e2a (commit) from 7cfa1717b812a126ce6f8e4cc32139164c89d789 (commit)
- Log ----------------------------------------------------------------- commit 51ba9ebd09bfa3569fee935ef7063394820cd333 Author: Rich Salz <rs...@akamai.com> Date: Fri Aug 16 18:05:08 2019 -0400 Avoid ?: construct in XXXerr calls It either makes the flow of control simpler and more obvious, or it is just a "cleanup" so that the editing scripts will find and fixup things. Reviewed-by: Dmitry Belyavskiy <beld...@gmail.com> Reviewed-by: Richard Levitte <levi...@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9441) commit 8c0e76813af6a886f66d3e95b908c6c924d2a6ad Author: Rich Salz <rs...@akamai.com> Date: Mon Aug 12 15:50:51 2019 -0400 Add merge-err-lines script Reviewed-by: Dmitry Belyavskiy <beld...@gmail.com> Reviewed-by: Richard Levitte <levi...@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9441) commit f6aca23e268799380e4e4193789ed96db1ed57f3 Author: Rich Salz <rs...@akamai.com> Date: Tue Jul 30 15:40:23 2019 -0400 Deprecate XXXerr() macros Actually, for transition, they're not really deprecated. Remove the "1 ||" from the ifdef line (in include/openssl/err.h) when ready to do this in production/"for real" Reviewed-by: Dmitry Belyavskiy <beld...@gmail.com> Reviewed-by: Richard Levitte <levi...@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9441) commit 0f17ac26fc552b7f233e8765e6b6a278c9731e2a Author: Rich Salz <rs...@akamai.com> Date: Wed Jul 24 11:40:07 2019 -0400 Add script convert XXerr to ERR_raise Reviewed-by: Dmitry Belyavskiy <beld...@gmail.com> Reviewed-by: Richard Levitte <levi...@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9441) ----------------------------------------------------------------------- Summary of changes: crypto/evp/evp_lib.c | 16 +++++----- crypto/evp/evp_locl.h | 4 +-- crypto/rand/drbg_lib.c | 7 +++-- include/openssl/err.h | 83 +++++++++++++++++++++++++------------------------- util/err-to-raise | 62 +++++++++++++++++++++++++++++++++++++ util/merge-err-lines | 29 ++++++++++++++++++ 6 files changed, 147 insertions(+), 54 deletions(-) create mode 100755 util/err-to-raise create mode 100755 util/merge-err-lines diff --git a/crypto/evp/evp_lib.c b/crypto/evp/evp_lib.c index e48c63037e..4ec880fd13 100644 --- a/crypto/evp/evp_lib.c +++ b/crypto/evp/evp_lib.c @@ -60,10 +60,10 @@ int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type) } } else ret = -1; - if (ret <= 0) - EVPerr(EVP_F_EVP_CIPHER_PARAM_TO_ASN1, ret == -2 ? - ASN1_R_UNSUPPORTED_CIPHER : - EVP_R_CIPHER_PARAMETER_ERROR); + if (ret == -2) + EVPerr(EVP_F_EVP_CIPHER_PARAM_TO_ASN1, ASN1_R_UNSUPPORTED_CIPHER); + else if (ret <= 0) + EVPerr(EVP_F_EVP_CIPHER_PARAM_TO_ASN1, EVP_R_CIPHER_PARAMETER_ERROR); if (ret < -1) ret = -1; return ret; @@ -106,10 +106,10 @@ int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type) } } else ret = -1; - if (ret <= 0) - EVPerr(EVP_F_EVP_CIPHER_ASN1_TO_PARAM, ret == -2 ? - EVP_R_UNSUPPORTED_CIPHER : - EVP_R_CIPHER_PARAMETER_ERROR); + if (ret == -2) + EVPerr(EVP_F_EVP_CIPHER_ASN1_TO_PARAM, EVP_R_UNSUPPORTED_CIPHER); + else if (ret <= 0) + EVPerr(EVP_F_EVP_CIPHER_ASN1_TO_PARAM, EVP_R_CIPHER_PARAMETER_ERROR); if (ret < -1) ret = -1; return ret; diff --git a/crypto/evp/evp_locl.h b/crypto/evp/evp_locl.h index ebfa3acd08..3437e04b67 100644 --- a/crypto/evp/evp_locl.h +++ b/crypto/evp/evp_locl.h @@ -233,7 +233,7 @@ OSSL_PARAM *evp_pkey_to_param(EVP_PKEY *pkey, size_t *sz); size_t pksize = (size_t)EVP_PKEY_size(ctx->pkey); \ \ if (pksize == 0) { \ - EVPerr(err, EVP_R_INVALID_KEY); /*ckerr_ignore*/ \ + ERR_raise(ERR_LIB_EVP, EVP_R_INVALID_KEY); /*ckerr_ignore*/ \ return 0; \ } \ if (arg == NULL) { \ @@ -241,7 +241,7 @@ OSSL_PARAM *evp_pkey_to_param(EVP_PKEY *pkey, size_t *sz); return 1; \ } \ if (*arglen < pksize) { \ - EVPerr(err, EVP_R_BUFFER_TOO_SMALL); /*ckerr_ignore*/ \ + ERR_raise(ERR_LIB_EVP, EVP_R_BUFFER_TOO_SMALL); /*ckerr_ignore*/ \ return 0; \ } \ } diff --git a/crypto/rand/drbg_lib.c b/crypto/rand/drbg_lib.c index c24222188f..bce2f74e9a 100644 --- a/crypto/rand/drbg_lib.c +++ b/crypto/rand/drbg_lib.c @@ -541,9 +541,10 @@ int RAND_DRBG_instantiate(RAND_DRBG *drbg, } if (drbg->state != DRBG_UNINITIALISED) { - RANDerr(RAND_F_RAND_DRBG_INSTANTIATE, - drbg->state == DRBG_ERROR ? RAND_R_IN_ERROR_STATE - : RAND_R_ALREADY_INSTANTIATED); + if (drbg->state == DRBG_ERROR) + RANDerr(RAND_F_RAND_DRBG_INSTANTIATE, RAND_R_IN_ERROR_STATE); + else + RANDerr(RAND_F_RAND_DRBG_INSTANTIATE, RAND_R_ALREADY_INSTANTIATED); goto end; } diff --git a/include/openssl/err.h b/include/openssl/err.h index d7427898c8..5c647831b5 100644 --- a/include/openssl/err.h +++ b/include/openssl/err.h @@ -108,48 +108,49 @@ struct err_state_st { # define ERR_LIB_USER 128 -# if ! OPENSSL_API_3 -# define SYSerr(f,r) ERR_raise(ERR_LIB_SYS,(r)) +# if 1 || !OPENSSL_API_3 +# define ASN1err(f, r) ERR_raise_data(ERR_LIB_ASN1, (r), NULL) +# define ASYNCerr(f, r) ERR_raise_data(ERR_LIB_ASYNC, (r), NULL) +# define BIOerr(f, r) ERR_raise_data(ERR_LIB_BIO, (r), NULL) +# define BNerr(f, r) ERR_raise_data(ERR_LIB_BN, (r), NULL) +# define BUFerr(f, r) ERR_raise_data(ERR_LIB_BUF, (r), NULL) +# define CMPerr(f, r) ERR_raise_data(ERR_LIB_CMP, (r), NULL) +# define CMSerr(f, r) ERR_raise_data(ERR_LIB_CMS, (r), NULL) +# define COMPerr(f, r) ERR_raise_data(ERR_LIB_COMP, (r), NULL) +# define CONFerr(f, r) ERR_raise_data(ERR_LIB_CONF, (r), NULL) +# define CRMFerr(f, r) ERR_raise_data(ERR_LIB_CRMF, (r), NULL) +# define CRYPTOerr(f, r) ERR_raise_data(ERR_LIB_CRYPTO, (r), NULL) +# define CTerr(f, r) ERR_raise_data(ERR_LIB_CT, (r), NULL) +# define DHerr(f, r) ERR_raise_data(ERR_LIB_DH, (r), NULL) +# define DSAerr(f, r) ERR_raise_data(ERR_LIB_DSA, (r), NULL) +# define DSOerr(f, r) ERR_raise_data(ERR_LIB_DSO, (r), NULL) +# define ECDHerr(f, r) ERR_raise_data(ERR_LIB_ECDH, (r), NULL) +# define ECDSAerr(f, r) ERR_raise_data(ERR_LIB_ECDSA, (r), NULL) +# define ECerr(f, r) ERR_raise_data(ERR_LIB_EC, (r), NULL) +# define ENGINEerr(f, r) ERR_raise_data(ERR_LIB_ENGINE, (r), NULL) +# define ESSerr(f, r) ERR_raise_data(ERR_LIB_ESS, (r), NULL) +# define EVPerr(f, r) ERR_raise_data(ERR_LIB_EVP, (r), NULL) +# define FIPSerr(f, r) ERR_raise_data(ERR_LIB_FIPS, (r), NULL) +# define HMACerr(f, r) ERR_raise_data(ERR_LIB_HMAC, (r), NULL) +# define KDFerr(f, r) ERR_raise_data(ERR_LIB_KDF, (r), NULL) +# define OBJerr(f, r) ERR_raise_data(ERR_LIB_OBJ, (r), NULL) +# define OCSPerr(f, r) ERR_raise_data(ERR_LIB_OCSP, (r), NULL) +# define OSSL_STOREerr(f, r) ERR_raise_data(ERR_LIB_OSSL_STORE, (r), NULL) +# define PEMerr(f, r) ERR_raise_data(ERR_LIB_PEM, (r), NULL) +# define PKCS12err(f, r) ERR_raise_data(ERR_LIB_PKCS12, (r), NULL) +# define PKCS7err(f, r) ERR_raise_data(ERR_LIB_PKCS7, (r), NULL) +# define PROPerr(f, r) ERR_raise_data(ERR_LIB_PROP, (r), NULL) +# define PROVerr(f, r) ERR_raise_data(ERR_LIB_PROV, (r), NULL) +# define RANDerr(f, r) ERR_raise_data(ERR_LIB_RAND, (r), NULL) +# define RSAerr(f, r) ERR_raise_data(ERR_LIB_RSA, (r), NULL) +# define SM2err(f, r) ERR_raise_data(ERR_LIB_SM2, (r), NULL) +# define SSLerr(f, r) ERR_raise_data(ERR_LIB_SSL, (r), NULL) +# define SYSerr(f, r) ERR_raise_data(ERR_LIB_SYS, (r), NULL) +# define TSerr(f, r) ERR_raise_data(ERR_LIB_TS, (r), NULL) +# define UIerr(f, r) ERR_raise_data(ERR_LIB_UI, (r), NULL) +# define X509V3err(f, r) ERR_raise_data(ERR_LIB_X509V3, (r), NULL) +# define X509err(f, r) ERR_raise_data(ERR_LIB_X509, (r), NULL) # endif -# define BNerr(f,r) ERR_raise(ERR_LIB_BN,(r)) -# define RSAerr(f,r) ERR_raise(ERR_LIB_RSA,(r)) -# define DHerr(f,r) ERR_raise(ERR_LIB_DH,(r)) -# define EVPerr(f,r) ERR_raise(ERR_LIB_EVP,(r)) -# define BUFerr(f,r) ERR_raise(ERR_LIB_BUF,(r)) -# define OBJerr(f,r) ERR_raise(ERR_LIB_OBJ,(r)) -# define PEMerr(f,r) ERR_raise(ERR_LIB_PEM,(r)) -# define DSAerr(f,r) ERR_raise(ERR_LIB_DSA,(r)) -# define X509err(f,r) ERR_raise(ERR_LIB_X509,(r)) -# define ASN1err(f,r) ERR_raise(ERR_LIB_ASN1,(r)) -# define CONFerr(f,r) ERR_raise(ERR_LIB_CONF,(r)) -# define CRYPTOerr(f,r) ERR_raise(ERR_LIB_CRYPTO,(r)) -# define ECerr(f,r) ERR_raise(ERR_LIB_EC,(r)) -# define SSLerr(f,r) ERR_raise(ERR_LIB_SSL,(r)) -# define BIOerr(f,r) ERR_raise(ERR_LIB_BIO,(r)) -# define PKCS7err(f,r) ERR_raise(ERR_LIB_PKCS7,(r)) -# define X509V3err(f,r) ERR_raise(ERR_LIB_X509V3,(r)) -# define PKCS12err(f,r) ERR_raise(ERR_LIB_PKCS12,(r)) -# define RANDerr(f,r) ERR_raise(ERR_LIB_RAND,(r)) -# define DSOerr(f,r) ERR_raise(ERR_LIB_DSO,(r)) -# define ENGINEerr(f,r) ERR_raise(ERR_LIB_ENGINE,(r)) -# define OCSPerr(f,r) ERR_raise(ERR_LIB_OCSP,(r)) -# define UIerr(f,r) ERR_raise(ERR_LIB_UI,(r)) -# define COMPerr(f,r) ERR_raise(ERR_LIB_COMP,(r)) -# define ECDSAerr(f,r) ERR_raise(ERR_LIB_ECDSA,(r)) -# define ECDHerr(f,r) ERR_raise(ERR_LIB_ECDH,(r)) -# define OSSL_STOREerr(f,r) ERR_raise(ERR_LIB_OSSL_STORE,(r)) -# define FIPSerr(f,r) ERR_raise(ERR_LIB_FIPS,(r)) -# define CMSerr(f,r) ERR_raise(ERR_LIB_CMS,(r)) -# define CRMFerr(f,r) ERR_raise(ERR_LIB_CRMF,(r)) -# define CMPerr(f,r) ERR_raise(ERR_LIB_CMP,(r)) -# define TSerr(f,r) ERR_raise(ERR_LIB_TS,(r)) -# define HMACerr(f,r) ERR_raise(ERR_LIB_HMAC,(r)) -# define CTerr(f,r) ERR_raise(ERR_LIB_CT,(r)) -# define ASYNCerr(f,r) ERR_raise(ERR_LIB_ASYNC,(r)) -# define SM2err(f,r) ERR_raise(ERR_LIB_SM2,(r)) -# define ESSerr(f,r) ERR_raise(ERR_LIB_ESS,(r)) -# define PROPerr(f,r) ERR_raise(ERR_LIB_PROP,(r)) -# define PROVerr(f,r) ERR_raise(ERR_LIB_PROV,(r)) # define ERR_PACK(l,f,r) ( \ (((unsigned int)(l) & 0x0FF) << 24L) | \ diff --git a/util/err-to-raise b/util/err-to-raise new file mode 100755 index 0000000000..a62ee3b790 --- /dev/null +++ b/util/err-to-raise @@ -0,0 +1,62 @@ +#! /usr/bin/env perl +# Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the Apache License 2.0 (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + +# Run this program like this: +# perl -pi util/err-to-error files... +# or +# git ls-files | grep '\.c$' | xargs perl -pi util/err-to-raise +# Consider running util/merge-err-lines first, to catch most (all?) of the +# cases where the XXXerr() call is split into two lines. + +# Also, what to do about the engines files? This includes: +# AFALGerr, CAPIerr, DASYNC, OSSLTEST +# There are about 70 such lines. + +use strict; +use warnings; + +s/ASN1err\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_ASN1, $1)/; +s/([^D])ASYNCerr\(\w+, *(\w+)\)/$1ERR_raise(ERR_LIB_ASYNC, $2)/; +s/BIOerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_BIO, $1)/; +s/BNerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_BN, $1)/; +s/BUFerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_BUF, $1)/; +s/CMPerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_CMP, $1)/; +s/CMSerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_CMS, $1)/; +s/COMPerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_COMP, $1)/; +s/CONFerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_CONF, $1)/; +s/CRMFerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_CRMF, $1)/; +s/CRYPTOerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_CRYPTO, $1)/; +s/CTerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_CT, $1)/; +s/DHerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_DH, $1)/; +s/DSAerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_DSA, $1)/; +s/DSOerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_DSO, $1)/; +s/ECDHerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_ECDH, $1)/; +s/ECDSAerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_ECDSA, $1)/; +s/ECerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_EC, $1)/; +s/ENGINEerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_ENGINE, $1)/; +s/ESSerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_ESS, $1)/; +s/EVPerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_EVP, $1)/; +s/FIPSerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_FIPS, $1)/; +s/KDFerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_KDF, $1)/; +s/OBJerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_OBJ, $1)/; +s/OCSPerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_OCSP, $1)/; +s/OSSL_STOREerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_OSSL_STORE, $1)/; +s/PEMerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_PEM, $1)/; +s/PKCS12err\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_PKCS12, $1)/; +s/PKCS7err\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_PKCS7, $1)/; +s/PROPerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_PROP, $1)/; +s/PROVerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_PROV, $1)/; +s/RANDerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_RAND, $1)/; +s/RSAerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_RSA, $1)/; +s/SM2err\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_SM2, $1)/; +s/SSLerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_SSL, $1)/; +s/SYSerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_SYS, $1)/; +s/TSerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_TS, $1)/; +s/UIerr\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_UI, $1)/; +s/X509V3err\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_X509V3, $1)/; +s/X509err\(\w+, *(\w+)\)/ERR_raise(ERR_LIB_X509, $1)/; diff --git a/util/merge-err-lines b/util/merge-err-lines new file mode 100755 index 0000000000..33644fa12e --- /dev/null +++ b/util/merge-err-lines @@ -0,0 +1,29 @@ +#! /usr/bin/env perl +# Copyright 2019 The OpenSSL Project Authors. All Rights Reserved. +# +# Licensed under the Apache License 2.0 (the "License"). You may not use +# this file except in compliance with the License. You can obtain a copy +# in the file LICENSE in the source distribution or at +# https://www.openssl.org/source/license.html + +# Sometimes calls to XXXerr() are split into two lines, because the define'd +# names are very long. This script looks for those lines and merges them. +# It should be run before the "err-to-raise" script. + +# Run this program like this: +# perl -pi util/merge-err-lines files... +# or +# git grep -l '[A-Z0-9]err([^)]*$' | xargs perl -pi util/merge-err-lines + +use strict; +use warnings; + +# Look for "{whitespace}XXXerr(no-close-paren{WHITESPACE}" lines +if ( /^ *[_A-Z0-9]+err\([^)]+ *$/ ) { + my $copy = $_; + chop($copy); + $copy =~ s/ +$//; + my $next = <>; + $next =~ s/^ +//; + $_ = $copy . ' ' . $next; +}