Skip to content

Commit d436868

Browse files
committed
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.
1 parent fe2d73c commit d436868

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

ext/openssl/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def find_openssl_library
172172

173173
# added in 3.0.0
174174
have_func("SSL_set0_tmp_dh_pkey")
175+
have_func("ERR_get_error_all")
175176

176177
Logging::message "=== Checking done. ===\n"
177178

ext/openssl/ossl.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -313,27 +313,31 @@ void
313313
ossl_clear_error(void)
314314
{
315315
if (dOSSL == Qtrue) {
316-
unsigned long e;
317-
const char *file, *data, *errstr;
318-
int line, flags;
319-
320-
while ((e = ERR_get_error_line_data(&file, &line, &data, &flags))) {
321-
errstr = ERR_error_string(e, NULL);
322-
if (!errstr)
323-
errstr = "(null)";
324-
325-
if (flags & ERR_TXT_STRING) {
326-
if (!data)
327-
data = "(null)";
328-
rb_warn("error on stack: %s (%s)", errstr, data);
329-
}
330-
else {
331-
rb_warn("error on stack: %s", errstr);
332-
}
333-
}
316+
unsigned long e;
317+
const char *file, *data, *func, *lib, *reason;
318+
char append[256] = "";
319+
int line, flags;
320+
321+
#ifdef HAVE_ERR_GET_ERROR_ALL
322+
while ((e = ERR_get_error_all(&file, &line, &func, &data, &flags))) {
323+
#else
324+
while ((e = ERR_get_error_line_data(&file, &line, &data, &flags))) {
325+
func = ERR_func_error_string(e);
326+
#endif
327+
lib = ERR_lib_error_string(e);
328+
reason = ERR_reason_error_string(e);
329+
330+
if (flags & ERR_TXT_STRING) {
331+
if (!data)
332+
data = "(null)";
333+
snprintf(append, sizeof(append), " (%s)", data);
334+
}
335+
rb_warn("error on stack: error:%08lX:%s:%s:%s%s", e, lib ? lib : "",
336+
func ? func : "", reason ? reason : "", append);
337+
}
334338
}
335339
else {
336-
ERR_clear_error();
340+
ERR_clear_error();
337341
}
338342
}
339343

0 commit comments

Comments
 (0)