diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2018-01-12 19:33:42 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2018-01-12 19:33:42 +0900 |
commit | 8bb88f13ad5c761f2104a6f8f37f718e119b3ce6 (patch) | |
tree | f9d510ac3ffd66117701cf3d93e5b7874b091e06 /ext/openssl/ossl_cipher.c | |
parent | 33a67ac96492828c1ea9d88e011da417d4ce7170 (diff) | |
download | ruby-openssl-8bb88f13ad5c761f2104a6f8f37f718e119b3ce6.tar.gz |
cipher: validate iterations argument for Cipher#pkcs5_keyivgenky/cipher-pkcs5-keyivgen-validate-iter
EVP_BytesToKey() internally converts the iteration count given as an
"int" into an "unsigned int". Calling that with a negative integer will
result in a hang. This is surprising, so let's validate the value by
ourselves and raise ArgumentError as necessary.
Diffstat (limited to 'ext/openssl/ossl_cipher.c')
-rw-r--r-- | ext/openssl/ossl_cipher.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/ext/openssl/ossl_cipher.c b/ext/openssl/ossl_cipher.c index 740f04b2..9e71c817 100644 --- a/ext/openssl/ossl_cipher.c +++ b/ext/openssl/ossl_cipher.c @@ -321,6 +321,8 @@ ossl_cipher_pkcs5_keyivgen(int argc, VALUE *argv, VALUE self) salt = (unsigned char *)RSTRING_PTR(vsalt); } iter = NIL_P(viter) ? 2048 : NUM2INT(viter); + if (iter <= 0) + rb_raise(rb_eArgError, "iterations must be a positive integer"); digest = NIL_P(vdigest) ? EVP_md5() : GetDigestPtr(vdigest); GetCipher(self, ctx); EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), digest, salt, |