summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2020-02-22 18:58:29 +0900
committerKazuki Yamaguchi <k@rhe.jp>2021-10-25 00:40:43 +0900
commit3d16401508c3efb44eefbb2d4dfb68b850407397 (patch)
tree15e26f6cd5ad23c8bfe190bea26430d5d8f116bb /ext/openssl
parent32d49e93cf958adf85eb12fa361f49f26d9559b7 (diff)
[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
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/extconf.rb1
-rw-r--r--ext/openssl/ossl.c42
2 files changed, 24 insertions, 19 deletions
diff --git a/ext/openssl/extconf.rb b/ext/openssl/extconf.rb
index 9a822f60ac7..baf36e94778 100644
--- a/ext/openssl/extconf.rb
+++ b/ext/openssl/extconf.rb
@@ -172,6 +172,7 @@ have_func("EVP_PKEY_check")
# added in 3.0.0
have_func("SSL_set0_tmp_dh_pkey")
+have_func("ERR_get_error_all")
Logging::message "=== Checking done. ===\n"
diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c
index c7a755ceda0..6c532aca949 100644
--- a/ext/openssl/ossl.c
+++ b/ext/openssl/ossl.c
@@ -313,27 +313,31 @@ void
ossl_clear_error(void)
{
if (dOSSL == Qtrue) {
- unsigned long e;
- const char *file, *data, *errstr;
- int line, flags;
-
- while ((e = ERR_get_error_line_data(&file, &line, &data, &flags))) {
- errstr = ERR_error_string(e, NULL);
- if (!errstr)
- errstr = "(null)";
-
- if (flags & ERR_TXT_STRING) {
- if (!data)
- data = "(null)";
- rb_warn("error on stack: %s (%s)", errstr, data);
- }
- else {
- rb_warn("error on stack: %s", errstr);
- }
- }
+ unsigned long e;
+ const char *file, *data, *func, *lib, *reason;
+ char append[256] = "";
+ int line, flags;
+
+#ifdef HAVE_ERR_GET_ERROR_ALL
+ while ((e = ERR_get_error_all(&file, &line, &func, &data, &flags))) {
+#else
+ 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 (!data)
+ data = "(null)";
+ snprintf(append, sizeof(append), " (%s)", data);
+ }
+ rb_warn("error on stack: error:%08lX:%s:%s:%s%s", e, lib ? lib : "",
+ func ? func : "", reason ? reason : "", append);
+ }
}
else {
- ERR_clear_error();
+ ERR_clear_error();
}
}