Skip to content

Commit

Permalink
pkey: fix interrupt handling in OpenSSL::PKey.generate_key
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rhenium committed Apr 4, 2021
1 parent 11801ad commit 88b90fb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ext/openssl/ossl_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ struct pkey_blocking_generate_arg {
int state;
int yield: 1;
int genparam: 1;
int stop: 1;
int interrupted: 1;
};

static VALUE
Expand All @@ -251,23 +251,31 @@ static int
pkey_gen_cb(EVP_PKEY_CTX *ctx)
{
struct pkey_blocking_generate_arg *arg = EVP_PKEY_CTX_get_app_data(ctx);
int state;

if (arg->yield) {
int state;
rb_protect(pkey_gen_cb_yield, (VALUE)ctx, &state);
if (state) {
arg->stop = 1;
arg->state = state;
return 0;
}
}
if (arg->interrupted) {
arg->interrupted = 0;
state = (int)(VALUE)rb_thread_call_with_gvl(call_check_ints, NULL);
if (state) {
arg->state = state;
return 0;
}
}
return !arg->stop;
return 1;
}

static void
pkey_blocking_gen_stop(void *ptr)
{
struct pkey_blocking_generate_arg *arg = ptr;
arg->stop = 1;
arg->interrupted = 1;
}

static void *
Expand Down

0 comments on commit 88b90fb

Please sign in to comment.