summaryrefslogtreecommitdiff
path: root/ext/openssl
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-09-12 15:40:57 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-09-12 22:49:03 +0900
commit598d66f6b2d1ab34dcd6db3bed70c59836a6206a (patch)
tree9bd09233ff30729eef29a1cbed86acca6caf715a /ext/openssl
parentc7dce12eb9e07f6ae35fc767760b862c10317e11 (diff)
[ruby/openssl] Separate formatting from ossl_make_error
Just append OpenSSL error reason to the given message string object, which would be alreadly formatted. Suppress -Wformat-security warning in `ossl_tsfac_create_ts`. https://github.com/ruby/openssl/commit/11b1d8a6b8
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/ossl.c25
-rw-r--r--ext/openssl/ossl.h2
-rw-r--r--ext/openssl/ossl_ts.c2
3 files changed, 16 insertions, 13 deletions
diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c
index 91cb54bfbeb..f214bcb5229 100644
--- a/ext/openssl/ossl.c
+++ b/ext/openssl/ossl.c
@@ -265,20 +265,14 @@ ossl_to_der_if_possible(VALUE obj)
return obj;
}
-PRINTF_ARGS(static VALUE ossl_make_error(VALUE exc, const char *fmt, va_list args), 2, 0);
-
/*
* Errors
*/
-static VALUE
-ossl_make_error(VALUE exc, const char *fmt, va_list args)
+VALUE
+ossl_make_error(VALUE exc, VALUE str)
{
- VALUE str = Qnil;
unsigned long e;
- if (fmt) {
- str = rb_vsprintf(fmt, args);
- }
e = ERR_peek_last_error();
if (e) {
const char *msg = ERR_reason_error_string(e);
@@ -302,10 +296,17 @@ ossl_raise(VALUE exc, const char *fmt, ...)
{
va_list args;
VALUE err;
- va_start(args, fmt);
- err = ossl_make_error(exc, fmt, args);
- va_end(args);
- rb_exc_raise(err);
+
+ if (fmt) {
+ va_start(args, fmt);
+ err = rb_vsprintf(fmt, args);
+ va_end(args);
+ }
+ else {
+ err = Qnil;
+ }
+
+ rb_exc_raise(ossl_make_error(exc, err));
}
void
diff --git a/ext/openssl/ossl.h b/ext/openssl/ossl.h
index 07d789e0f86..65d022c7f31 100644
--- a/ext/openssl/ossl.h
+++ b/ext/openssl/ossl.h
@@ -121,6 +121,8 @@ int ossl_pem_passwd_cb(char *, int, int, void *);
* ERRor messages
*/
PRINTF_ARGS(NORETURN(void ossl_raise(VALUE, const char *, ...)), 2, 3);
+/* Make exception instance from str and OpenSSL error reason string. */
+VALUE ossl_make_error(VALUE exc, VALUE str);
/* Clear OpenSSL error queue. If dOSSL is set, rb_warn() them. */
void ossl_clear_error(void);
diff --git a/ext/openssl/ossl_ts.c b/ext/openssl/ossl_ts.c
index 4654babfcf9..dbd73748a90 100644
--- a/ext/openssl/ossl_ts.c
+++ b/ext/openssl/ossl_ts.c
@@ -1223,7 +1223,7 @@ end:
ASN1_OBJECT_free(def_policy_id_obj);
TS_RESP_CTX_free(ctx);
if (err_msg)
- ossl_raise(eTimestampError, err_msg);
+ rb_exc_raise(ossl_make_error(eTimestampError, rb_str_new_cstr(err_msg)));
if (status)
rb_jump_tag(status);
return ret;