[ruby/openssl] ossl.c: use ERR_get_error_all() if available

OpenSSL 3.0 deprecated ERR_get_error_line_data() in favor of
ERR_get_error_all(), as part of the error queue structure changes.

https://github.com/ruby/openssl/commit/8e98d2ecc8
This commit is contained in:
Kazuki Yamaguchi 2020-02-22 18:58:29 +09:00
parent 32d49e93cf
commit 3d16401508
2 changed files with 22 additions and 17 deletions

View File

@ -172,6 +172,7 @@ have_func("EVP_PKEY_check")
# added in 3.0.0 # added in 3.0.0
have_func("SSL_set0_tmp_dh_pkey") have_func("SSL_set0_tmp_dh_pkey")
have_func("ERR_get_error_all")
Logging::message "=== Checking done. ===\n" Logging::message "=== Checking done. ===\n"

View File

@ -313,27 +313,31 @@ void
ossl_clear_error(void) ossl_clear_error(void)
{ {
if (dOSSL == Qtrue) { if (dOSSL == Qtrue) {
unsigned long e; unsigned long e;
const char *file, *data, *errstr; const char *file, *data, *func, *lib, *reason;
int line, flags; char append[256] = "";
int line, flags;
while ((e = ERR_get_error_line_data(&file, &line, &data, &flags))) { #ifdef HAVE_ERR_GET_ERROR_ALL
errstr = ERR_error_string(e, NULL); while ((e = ERR_get_error_all(&file, &line, &func, &data, &flags))) {
if (!errstr) #else
errstr = "(null)"; while ((e = ERR_get_error_line_data(&file, &line, &data, &flags))) {
func = ERR_func_error_string(e);
#endif
lib = ERR_lib_error_string(e);
reason = ERR_reason_error_string(e);
if (flags & ERR_TXT_STRING) { if (flags & ERR_TXT_STRING) {
if (!data) if (!data)
data = "(null)"; data = "(null)";
rb_warn("error on stack: %s (%s)", errstr, data); snprintf(append, sizeof(append), " (%s)", data);
} }
else { rb_warn("error on stack: error:%08lX:%s:%s:%s%s", e, lib ? lib : "",
rb_warn("error on stack: %s", errstr); func ? func : "", reason ? reason : "", append);
} }
}
} }
else { else {
ERR_clear_error(); ERR_clear_error();
} }
} }