aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl/ossl_rand.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-29 17:41:56 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-05-29 17:41:56 +0000
commit2745d527b34b7f87ab7684b1451465e5e2ed8880 (patch)
tree2f33c383504947747de3a4b93edc7cd723b545ad /ext/openssl/ossl_rand.c
parent9df121034a09aced529bf50e0ae2226baaaeb925 (diff)
downloadruby-2745d527b34b7f87ab7684b1451465e5e2ed8880.tar.gz
* 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
Diffstat (limited to 'ext/openssl/ossl_rand.c')
-rw-r--r--ext/openssl/ossl_rand.c16
1 files changed, 10 insertions, 6 deletions
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;