Skip to content

Commit 88b90fb

Browse files
committed
pkey: fix interrupt handling in OpenSSL::PKey.generate_key
rb_thread_call_without_gvl() can be interrupted, but it may be able to resume the operation. Call rb_thread_check_ints() to see if it raises an exception or not.
1 parent 11801ad commit 88b90fb

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

ext/openssl/ossl_pkey.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ struct pkey_blocking_generate_arg {
229229
int state;
230230
int yield: 1;
231231
int genparam: 1;
232-
int stop: 1;
232+
int interrupted: 1;
233233
};
234234

235235
static VALUE
@@ -251,23 +251,31 @@ static int
251251
pkey_gen_cb(EVP_PKEY_CTX *ctx)
252252
{
253253
struct pkey_blocking_generate_arg *arg = EVP_PKEY_CTX_get_app_data(ctx);
254+
int state;
254255

255256
if (arg->yield) {
256-
int state;
257257
rb_protect(pkey_gen_cb_yield, (VALUE)ctx, &state);
258258
if (state) {
259-
arg->stop = 1;
260259
arg->state = state;
260+
return 0;
261+
}
262+
}
263+
if (arg->interrupted) {
264+
arg->interrupted = 0;
265+
state = (int)(VALUE)rb_thread_call_with_gvl(call_check_ints, NULL);
266+
if (state) {
267+
arg->state = state;
268+
return 0;
261269
}
262270
}
263-
return !arg->stop;
271+
return 1;
264272
}
265273

266274
static void
267275
pkey_blocking_gen_stop(void *ptr)
268276
{
269277
struct pkey_blocking_generate_arg *arg = ptr;
270-
arg->stop = 1;
278+
arg->interrupted = 1;
271279
}
272280

273281
static void *

0 commit comments

Comments
 (0)