1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

ossl.c: check integer overflow

* ext/openssl/ossl.c (Init_ossl_locks): check integer overflow.
  OPENSSL_malloc() takes int only.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-07-10 02:19:47 +00:00
parent 1734e481af
commit c341e85b1c

View file

@ -480,9 +480,13 @@ static unsigned long ossl_thread_id(void)
static void Init_ossl_locks(void)
{
int i;
int num_locks = CRYPTO_num_locks();
ossl_locks = (VALUE*) OPENSSL_malloc(CRYPTO_num_locks() * sizeof(VALUE));
for (i = 0; i < CRYPTO_num_locks(); i++) {
if ((unsigned)num_locks >= INT_MAX / (int)sizeof(VALUE)) {
rb_raise(rb_eRuntimeError, "CRYPTO_num_locks() is too big: %d", num_locks);
}
ossl_locks = (VALUE*) OPENSSL_malloc(num_locks * (int)sizeof(VALUE));
for (i = 0; i < num_locks; i++) {
ossl_locks[i] = rb_mutex_new();
rb_global_variable(&(ossl_locks[i]));
}