From add8c8e9647a71cc755dea22490e2075e342624b Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Wed, 24 Jul 2019 13:25:56 +0200 Subject: [PATCH] ERR: Remove ERR_put_func_error() and reimplement ERR_put_error() as a macro Also, deprecate ERR_put_error() Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/9452) --- crypto/err/err.c | 38 -------------------------------------- doc/man3/ERR_put_error.pod | 24 +++++++++++------------- include/openssl/err.h | 11 ++++++++--- test/errtest.c | 8 +++++--- util/libcrypto.num | 4 ++-- util/private.num | 1 + 6 files changed, 27 insertions(+), 59 deletions(-) diff --git a/crypto/err/err.c b/crypto/err/err.c index 60f945c845..f129c1c7d6 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -355,44 +355,6 @@ void err_free_strings_int(void) /********************************************************/ -void ERR_put_func_error(int lib, const char *func, int reason, - const char *file, int line) -{ - ERR_put_error(lib, 0, reason, file, line); - ERR_add_error_data(2, "calling function ", func); -} - -void ERR_put_error(int lib, int func, int reason, const char *file, int line) -{ - ERR_STATE *es; - -#ifdef _OSD_POSIX - /* - * In the BS2000-OSD POSIX subsystem, the compiler generates path names - * in the form "*POSIX(/etc/passwd)". This dirty hack strips them to - * something sensible. @@@ We shouldn't modify a const string, though. - */ - if (strncmp(file, "*POSIX(", sizeof("*POSIX(") - 1) == 0) { - char *end; - - /* Skip the "*POSIX(" prefix */ - file += sizeof("*POSIX(") - 1; - end = &file[strlen(file) - 1]; - if (*end == ')') - *end = '\0'; - /* Optional: use the basename of the path only. */ - if ((end = strrchr(file, '/')) != NULL) - file = &end[1]; - } -#endif - es = ERR_get_state(); - if (es == NULL) - return; - - err_get_slot(es); - err_clear(es, es->top, 0); -} - void ERR_clear_error(void) { int i; diff --git a/doc/man3/ERR_put_error.pod b/doc/man3/ERR_put_error.pod index d9bbba99a0..729eb574ce 100644 --- a/doc/man3/ERR_put_error.pod +++ b/doc/man3/ERR_put_error.pod @@ -3,8 +3,8 @@ =head1 NAME ERR_raise, ERR_raise_data, -ERR_put_error, ERR_put_func_error, -ERR_add_error_data, ERR_add_error_vdata - record an error +ERR_put_error, ERR_add_error_data, ERR_add_error_vdata +- record an error =head1 SYNOPSIS @@ -13,13 +13,13 @@ ERR_add_error_data, ERR_add_error_vdata - record an error void ERR_raise(int lib, int reason); void ERR_raise_data(int lib, int reason, const char *fmt, ...); - void ERR_put_error(int lib, int func, int reason, const char *file, int line); - void ERR_put_func_error(int lib, const char *func, int reason, - const char *file, int line); - void ERR_add_error_data(int num, ...); void ERR_add_error_vdata(int num, va_list arg); +Deprecated since OpenSSL 3.0: + + void ERR_put_error(int lib, int func, int reason, const char *file, int line); + =head1 DESCRIPTION ERR_raise() adds a new error to the thread's error queue. The @@ -37,10 +37,6 @@ signals that the error of reason code B occurred in function B of library B, in line number B of B. This function is usually called by a macro. -ERR_put_func_err() is similar except that the B is a string naming -a function external to OpenSSL, usually provided by the platform on which -OpenSSL and the application is running. - ERR_add_error_data() associates the concatenation of its B string arguments with the error code added last. ERR_add_error_vdata() is similar except the argument is a B. @@ -52,6 +48,8 @@ error messages for the error code. =head2 Reporting errors +=for comment TODO(3.0) should this be internal documentation? + Each sub-library has a specific macro XXXerr() that is used to report errors. Its first argument is a function code B, the second argument is a reason code B. Function codes are derived @@ -78,12 +76,12 @@ the ASN1err() macro. =head1 RETURN VALUES -ERR_raise(), ERR_put_error() and ERR_add_error_data() -return no values. +ERR_raise(), ERR_put_error(), ERR_add_error_data() and +ERR_add_error_vdata() return no values. =head1 NOTES -ERR_raise() is implemented as a macro. +ERR_raise() and ERR_put_error() are implemented as macros. =head1 SEE ALSO diff --git a/include/openssl/err.h b/include/openssl/err.h index 7aac9b88d4..142321d2c8 100644 --- a/include/openssl/err.h +++ b/include/openssl/err.h @@ -252,9 +252,14 @@ void ERR_vset_error(int lib, int reason, const char *fmt, va_list args); ERR_set_debug(OPENSSL_FILE,OPENSSL_LINE,OPENSSL_FUNC), \ ERR_set_error) -void ERR_put_error(int lib, int func, int reason, const char *file, int line); -void ERR_put_func_error(int lib, const char *func, int reason, - const char *file, int line); +#if !OPENSSL_API_3 +/* Backward compatibility */ +#define ERR_put_error(lib, func, reason, file, line) \ + (ERR_new(), \ + ERR_set_debug((file), (line), NULL), \ + ERR_set_error((lib), (reason), NULL)) +#endif + void ERR_set_error_data(char *data, int flags); unsigned long ERR_get_error(void); diff --git a/test/errtest.c b/test/errtest.c index 88ff860092..1a18335b6e 100644 --- a/test/errtest.c +++ b/test/errtest.c @@ -47,12 +47,14 @@ static int vdata_appends(void) /* Test that setting a platform error sets the right values. */ static int platform_error(void) { - const char *file = __FILE__, *f, *data; - const int line = __LINE__; + const char *file, *f, *data; + int line; int l; unsigned long e; - ERR_put_func_error(ERR_LIB_SYS, "exit", ERR_R_INTERNAL_ERROR, file, line); + file = __FILE__; + line = __LINE__ + 1; /* The error is generated on the next line */ + FUNCerr("exit", ERR_R_INTERNAL_ERROR); if (!TEST_ulong_ne(e = ERR_get_error_line_data(&f, &l, &data, NULL), 0) || !TEST_int_eq(ERR_GET_REASON(e), ERR_R_INTERNAL_ERROR) || !TEST_int_eq(l, line) diff --git a/util/libcrypto.num b/util/libcrypto.num index da7395c9cb..a6c5097e1c 100644 --- a/util/libcrypto.num +++ b/util/libcrypto.num @@ -998,7 +998,7 @@ OPENSSL_LH_get_down_load 1023 3_0_0 EXIST::FUNCTION: EVP_md4 1024 3_0_0 EXIST::FUNCTION:MD4 X509_set_subject_name 1025 3_0_0 EXIST::FUNCTION: i2d_PKCS8PrivateKey_nid_bio 1026 3_0_0 EXIST::FUNCTION: -ERR_put_error 1027 3_0_0 EXIST::FUNCTION: +ERR_put_error 1027 3_0_0 NOEXIST::FUNCTION: ERR_add_error_data 1028 3_0_0 EXIST::FUNCTION: X509_ALGORS_it 1029 3_0_0 EXIST::FUNCTION: MD5_Update 1030 3_0_0 EXIST::FUNCTION:MD5 @@ -4690,7 +4690,7 @@ EVP_KEYMGMT_up_ref 4795 3_0_0 EXIST::FUNCTION: EVP_KEYMGMT_free 4796 3_0_0 EXIST::FUNCTION: EVP_KEYMGMT_provider 4797 3_0_0 EXIST::FUNCTION: X509_PUBKEY_dup 4798 3_0_0 EXIST::FUNCTION: -ERR_put_func_error 4799 3_0_0 EXIST::FUNCTION: +ERR_put_func_error 4799 3_0_0 NOEXIST::FUNCTION: EVP_MD_name 4800 3_0_0 EXIST::FUNCTION: EVP_CIPHER_name 4801 3_0_0 EXIST::FUNCTION: EVP_MD_provider 4802 3_0_0 EXIST::FUNCTION: diff --git a/util/private.num b/util/private.num index 3c00589c9b..82cb72e606 100644 --- a/util/private.num +++ b/util/private.num @@ -195,6 +195,7 @@ ERR_GET_LIB define ERR_GET_REASON define ERR_PACK define ERR_free_strings define deprecated 1.1.0 +ERR_put_error define deprecated 3.0 ERR_load_crypto_strings define deprecated 1.1.0 ERR_raise define ERR_raise_data define -- 2.25.1