[前][次][番号順一覧][スレッド一覧]

ruby-changes:67958

From: Nobuyoshi <ko1@a...>
Date: Mon, 13 Sep 2021 00:51:22 +0900 (JST)
Subject: [ruby-changes:67958] 598d66f6b2 (master): [ruby/openssl] Separate formatting from ossl_make_error

https://git.ruby-lang.org/ruby.git/commit/?id=598d66f6b2

From 598d66f6b2d1ab34dcd6db3bed70c59836a6206a Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 12 Sep 2021 15:40:57 +0900
Subject: [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
---
 ext/openssl/ossl.c    | 25 +++++++++++++------------
 ext/openssl/ossl.h    |  2 ++
 ext/openssl/ossl_ts.c |  2 +-
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c
index 91cb54b..f214bcb 100644
--- a/ext/openssl/ossl.c
+++ b/ext/openssl/ossl.c
@@ -265,20 +265,14 @@ ossl_to_der_if_possible(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L265
     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, ...) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.c#L296
 {
     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 07d789e..65d022c 100644
--- a/ext/openssl/ossl.h
+++ b/ext/openssl/ossl.h
@@ -121,6 +121,8 @@ int ossl_pem_passwd_cb(char *, int, int, void *); https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl.h#L121
  * 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 4654bab..dbd7374 100644
--- a/ext/openssl/ossl_ts.c
+++ b/ext/openssl/ossl_ts.c
@@ -1223,7 +1223,7 @@ end: https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ts.c#L1223
     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;
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]