diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2021-04-05 00:30:01 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2021-04-05 00:41:42 +0900 |
commit | 88b90fb8568a9f104dfed1ace3b33b8586eafeed (patch) | |
tree | 34c7129dd93c26779f6f57686ea106a7c73c3764 | |
parent | 11801ad6b12895329e00220599fba100746a9137 (diff) | |
download | ruby-openssl-88b90fb8568a9f104dfed1ace3b33b8586eafeed.tar.gz |
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.
-rw-r--r-- | ext/openssl/ossl_pkey.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c index 1c1f80bf..fce647d8 100644 --- a/ext/openssl/ossl_pkey.c +++ b/ext/openssl/ossl_pkey.c @@ -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 @@ -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 * |