Browse Source

ERR: Remove ERR_put_func_error() and reimplement ERR_put_error() as a macro

Also, deprecate ERR_put_error()

Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9452)
master
Richard Levitte 3 years ago
parent
commit
add8c8e964
6 changed files with 27 additions and 59 deletions
  1. +0
    -38
      crypto/err/err.c
  2. +11
    -13
      doc/man3/ERR_put_error.pod
  3. +8
    -3
      include/openssl/err.h
  4. +5
    -3
      test/errtest.c
  5. +2
    -2
      util/libcrypto.num
  6. +1
    -0
      util/private.num

+ 0
- 38
crypto/err/err.c View File

@ -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;


+ 11
- 13
doc/man3/ERR_put_error.pod View File

@ -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<reason> occurred in function
B<func> of library B<lib>, in line number B<line> of B<file>.
This function is usually called by a macro.
ERR_put_func_err() is similar except that the B<func> 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<num> string
arguments with the error code added last.
ERR_add_error_vdata() is similar except the argument is a B<va_list>.
@ -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<XXX_F_...>, the second
argument is a reason code B<XXX_R_...>. 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


+ 8
- 3
include/openssl/err.h View File

@ -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);


+ 5
- 3
test/errtest.c View File

@ -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)


+ 2
- 2
util/libcrypto.num View File

@ -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:


+ 1
- 0
util/private.num View File

@ -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


Loading…
Cancel
Save