diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2022-08-11 17:52:31 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-11 17:52:31 +0900 |
commit | d52549a186b38735e53e5ff3315be69a02938bba (patch) | |
tree | 7bac4e2ed1e19fe0eee10f07ca1b23506981351b | |
parent | ee64d93cb20e7fca80eddbf711c56ae2fac9a825 (diff) | |
parent | ef2352521089998842672106d2c988387ffb6698 (diff) | |
download | ruby-openssl-d52549a186b38735e53e5ff3315be69a02938bba.tar.gz |
Merge pull request #531 from no6v/pkey-sign-option-type-check
OpenSSL::PKey::PKey#sign etc. with wrong type option causes SEGV
-rw-r--r-- | ext/openssl/ossl_pkey.c | 1 | ||||
-rw-r--r-- | test/openssl/test_pkey_rsa.rb | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c index 2a4835a2..7fcb570c 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 4bb39ed4..fa84b76f 100644 --- a/test/openssl/test_pkey_rsa.rb +++ b/test/openssl/test_pkey_rsa.rb @@ -108,6 +108,11 @@ class OpenSSL::TestPKeyRSA < OpenSSL::PKeyTestCase 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 |