From 2745d527b34b7f87ab7684b1451465e5e2ed8880 Mon Sep 17 00:00:00 2001 From: knu Date: Thu, 29 May 2008 17:41:56 +0000 Subject: * ext/openssl/ossl_bn.c (ossl_bn_s_rand, ossl_bn_s_pseudo_rand), ext/openssl/ossl_pkey_dh.c (ossl_dh_s_generate) (ossl_dh_initialize), ext/openssl/ossl_pkey_dsa.c (ossl_dsa_s_generate), ext/openssl/ossl_rand.c (ossl_rand_bytes) (ossl_rand_pseudo_bytes, ossl_rand_egd_bytes), ext/openssl/ossl_x509store.c (ossl_x509stctx_set_error): Do not use FIX2INT() without checking the value type. Use NUM2INT() instead; found by akr in [ruby-dev:34890]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/openssl/ossl_rand.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'ext/openssl/ossl_rand.c') diff --git a/ext/openssl/ossl_rand.c b/ext/openssl/ossl_rand.c index c22a7357b0..d9c1a7f34f 100644 --- a/ext/openssl/ossl_rand.c +++ b/ext/openssl/ossl_rand.c @@ -96,9 +96,10 @@ static VALUE ossl_rand_bytes(VALUE self, VALUE len) { VALUE str; - - str = rb_str_new(0, FIX2INT(len)); - if (!RAND_bytes(RSTRING_PTR(str), FIX2INT(len))) { + long n = NUM2INT(len); + + str = rb_str_new(0, n); + if (!RAND_bytes(RSTRING_PTR(str), n)) { ossl_raise(eRandomError, NULL); } @@ -114,9 +115,10 @@ static VALUE ossl_rand_pseudo_bytes(VALUE self, VALUE len) { VALUE str; + long n = NUM2INT(len); - str = rb_str_new(0, FIX2INT(len)); - if (!RAND_pseudo_bytes(RSTRING_PTR(str), FIX2INT(len))) { + str = rb_str_new(0, n); + if (!RAND_pseudo_bytes(RSTRING_PTR(str), n)) { ossl_raise(eRandomError, NULL); } @@ -147,9 +149,11 @@ ossl_rand_egd(VALUE self, VALUE filename) static VALUE ossl_rand_egd_bytes(VALUE self, VALUE filename, VALUE len) { + long n = NUM2INT(len); + SafeStringValue(filename); - if (!RAND_egd_bytes(RSTRING_PTR(filename), FIX2INT(len))) { + if (!RAND_egd_bytes(RSTRING_PTR(filename), n)) { ossl_raise(eRandomError, NULL); } return Qtrue; -- cgit v1.2.3