Skip to content

Commit 11b1d8a

Browse files
committed
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`.
1 parent 41da295 commit 11b1d8a

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

ext/openssl/ossl.c

+13-12
Original file line numberDiff line numberDiff line change
@@ -265,20 +265,14 @@ ossl_to_der_if_possible(VALUE obj)
265265
return obj;
266266
}
267267

268-
PRINTF_ARGS(static VALUE ossl_make_error(VALUE exc, const char *fmt, va_list args), 2, 0);
269-
270268
/*
271269
* Errors
272270
*/
273-
static VALUE
274-
ossl_make_error(VALUE exc, const char *fmt, va_list args)
271+
VALUE
272+
ossl_make_error(VALUE exc, VALUE str)
275273
{
276-
VALUE str = Qnil;
277274
unsigned long e;
278275

279-
if (fmt) {
280-
str = rb_vsprintf(fmt, args);
281-
}
282276
e = ERR_peek_last_error();
283277
if (e) {
284278
const char *msg = ERR_reason_error_string(e);
@@ -302,10 +296,17 @@ ossl_raise(VALUE exc, const char *fmt, ...)
302296
{
303297
va_list args;
304298
VALUE err;
305-
va_start(args, fmt);
306-
err = ossl_make_error(exc, fmt, args);
307-
va_end(args);
308-
rb_exc_raise(err);
299+
300+
if (fmt) {
301+
va_start(args, fmt);
302+
err = rb_vsprintf(fmt, args);
303+
va_end(args);
304+
}
305+
else {
306+
err = Qnil;
307+
}
308+
309+
rb_exc_raise(ossl_make_error(exc, err));
309310
}
310311

311312
void

ext/openssl/ossl.h

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ int ossl_pem_passwd_cb(char *, int, int, void *);
121121
* ERRor messages
122122
*/
123123
PRINTF_ARGS(NORETURN(void ossl_raise(VALUE, const char *, ...)), 2, 3);
124+
/* Make exception instance from str and OpenSSL error reason string. */
125+
VALUE ossl_make_error(VALUE exc, VALUE str);
124126
/* Clear OpenSSL error queue. If dOSSL is set, rb_warn() them. */
125127
void ossl_clear_error(void);
126128

ext/openssl/ossl_ts.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ ossl_tsfac_create_ts(VALUE self, VALUE key, VALUE certificate, VALUE request)
12231223
ASN1_OBJECT_free(def_policy_id_obj);
12241224
TS_RESP_CTX_free(ctx);
12251225
if (err_msg)
1226-
ossl_raise(eTimestampError, err_msg);
1226+
rb_exc_raise(ossl_make_error(eTimestampError, rb_str_new_cstr(err_msg)));
12271227
if (status)
12281228
rb_jump_tag(status);
12291229
return ret;

0 commit comments

Comments
 (0)