diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2018-07-02 16:02:27 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2018-07-02 16:02:27 +0900 |
commit | 6de46ccb2cca55ab5383dbf1306a8ec83698ecac (patch) | |
tree | 91534e9d86849c26c10bd30f75d0088c03e7f7ef | |
parent | fdcda971a26895ea5c5015a90671ee73039d55e8 (diff) | |
download | ruby-openssl-6de46ccb2cca55ab5383dbf1306a8ec83698ecac.tar.gz |
-rw-r--r-- | ext/openssl/ossl.c | 83 | ||||
-rw-r--r-- | test/test_pkcs7.rb | 2 |
2 files changed, 57 insertions, 28 deletions
diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c index 245385e7..9ea9013c 100644 --- a/ext/openssl/ossl.c +++ b/ext/openssl/ossl.c @@ -262,27 +262,68 @@ ossl_to_der_if_possible(VALUE obj) /* * Errors */ +static void +error_debug_print(unsigned long e, const char *file, int line, + const char *data, int flags) +{ + const char *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); + } +} + static VALUE ossl_make_error(VALUE exc, const char *fmt, va_list args) { - VALUE str = Qnil; unsigned long e; + const char *file, *data; + int line, flags; + VALUE str = Qnil; - if (fmt) { - str = rb_vsprintf(fmt, args); - } - e = ERR_peek_last_error(); - if (e) { - const char *msg = ERR_reason_error_string(e); + while ((e = ERR_get_error_line_data(&file, &line, &data, &flags))) { + VALUE errstr; + const char *reason = ERR_reason_error_string(e); + if (!reason) + reason = "(null)"; - if (NIL_P(str)) { - if (msg) str = rb_str_new_cstr(msg); + if (flags & ERR_TXT_STRING) { + if (!data) + data = "(null)"; + errstr = rb_sprintf("%s (%s)", reason, data); } else { - if (RSTRING_LEN(str)) rb_str_cat2(str, ": "); - rb_str_cat2(str, msg ? msg : "(null)"); + errstr = rb_str_new_cstr(reason); } - ossl_clear_error(); + + if (NIL_P(str)) { + if (!ERR_peek_last_error()) { + str = errstr; + break; + } + str = rb_str_new_cstr("errors on queue:"); + } + rb_str_cat_cstr(str, "\n\t"); + rb_str_buf_append(str, errstr); + + if (dOSSL == Qtrue) + error_debug_print(e, file, line, data, flags); + } + + if (fmt) { + VALUE msg = rb_vsprintf(fmt, args); + if (!NIL_P(str)) { + rb_str_cat_cstr(msg, ": "); + rb_str_buf_append(msg, str); + } + str = msg; } if (NIL_P(str)) str = rb_str_new(0, 0); @@ -305,23 +346,11 @@ ossl_clear_error(void) { if (dOSSL == Qtrue) { unsigned long e; - const char *file, *data, *errstr; + const char *file, *data; 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); - } - } + while ((e = ERR_get_error_line_data(&file, &line, &data, &flags))) + error_debug_print(e, file, line, data, flags); } else { ERR_clear_error(); diff --git a/test/test_pkcs7.rb b/test/test_pkcs7.rb index 6437112b..f0f87ab6 100644 --- a/test/test_pkcs7.rb +++ b/test/test_pkcs7.rb @@ -139,7 +139,7 @@ class OpenSSL::TestPKCS7 < OpenSSL::TestCase def test_graceful_parsing_failure #[ruby-core:43250] contents = File.read(__FILE__) - assert_raise(ArgumentError) { OpenSSL::PKCS7.new(contents) } + assert_raise(RuntimeError) { OpenSSL::PKCS7.new(contents) } end def test_set_type_signed |