From ef2352521089998842672106d2c988387ffb6698 Mon Sep 17 00:00:00 2001 From: Nobuhiro IMAI Date: Fri, 5 Aug 2022 18:42:06 +0900 Subject: [PATCH] Check if the option is an Hash in `pkey_ctx_apply_options0()` causes SEGV if it is an Array or something like that. --- ext/openssl/ossl_pkey.c | 1 + test/openssl/test_pkey_rsa.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c index 2a4835a28..7fcb570c2 100644 --- a/ext/openssl/ossl_pkey.c +++ b/ext/openssl/ossl_pkey.c @@ -200,6 +200,7 @@ static VALUE pkey_ctx_apply_options0(VALUE args_v) { VALUE *args = (VALUE *)args_v; + Check_Type(args[1], T_HASH); rb_block_call(args[1], rb_intern("each"), 0, NULL, pkey_ctx_apply_options_i, args[0]); diff --git a/test/openssl/test_pkey_rsa.rb b/test/openssl/test_pkey_rsa.rb index 4bb39ed4a..fa84b76f4 100644 --- a/test/openssl/test_pkey_rsa.rb +++ b/test/openssl/test_pkey_rsa.rb @@ -108,6 +108,11 @@ def test_sign_verify_options salt_length: 20, mgf1_hash: "SHA1") # Defaults to PKCS #1 v1.5 padding => verification failure assert_equal false, key.verify("SHA256", sig_pss, data) + + # option type check + assert_raise_with_message(TypeError, /expected Hash/) { + key.sign("SHA256", data, ["x"]) + } end def test_sign_verify_raw