aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-23 10:47:37 +0000
committerrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-23 10:47:37 +0000
commitbb900ff48b2358003c8b46d4699212a3c28aa8db (patch)
tree5af9e585dcd086019bd50048e8dfa0e837135b0f
parentd29cd7ac3ca1e9c912e11f3a8251e302ea52e16c (diff)
downloadruby-bb900ff48b2358003c8b46d4699212a3c28aa8db.tar.gz
openssl: fix incorrect return value check of RAND_* functions
* ext/openssl/ossl_rand.c (ossl_rand_egd, ossl_rand_egd_bytes): RAND_egd{_bytes,}() return -1 on failure, not 0. Patch by cremno phobia <cremno@mail.ru> [ruby-core:63795] [Bug #10053] (ossl_pseudo_bytes): Similar, RAND_pseudo_bytes() may return 0 or -1 on failure. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55132 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--ext/openssl/ossl_rand.c12
2 files changed, 14 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index e76ead4c1c..312e9e3fd3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Mon May 23 19:41:27 2016 Kazuki Yamaguchi <k@rhe.jp>
+
+ * ext/openssl/ossl_rand.c (ossl_rand_egd, ossl_rand_egd_bytes):
+ RAND_egd{_bytes,}() return -1 on failure, not 0.
+ Patch by cremno phobia <cremno@mail.ru>
+ [ruby-core:63795] [Bug #10053]
+ (ossl_pseudo_bytes): Similar, RAND_pseudo_bytes() may return 0 or
+ -1 on failure.
+
Mon May 23 15:52:07 2016 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/bigdecimal/bigdecimal.c (isfinite): isfinite does not always
diff --git a/ext/openssl/ossl_rand.c b/ext/openssl/ossl_rand.c
index daf866d772..7a01278ac8 100644
--- a/ext/openssl/ossl_rand.c
+++ b/ext/openssl/ossl_rand.c
@@ -114,10 +114,8 @@ ossl_rand_bytes(VALUE self, VALUE len)
str = rb_str_new(0, n);
ret = RAND_bytes((unsigned char *)RSTRING_PTR(str), n);
- if (ret == 0){
- char buf[256];
- ERR_error_string_n(ERR_get_error(), buf, 256);
- ossl_raise(eRandomError, "RAND_bytes error: %s", buf);
+ if (ret == 0) {
+ ossl_raise(eRandomError, "RAND_bytes");
} else if (ret == -1) {
ossl_raise(eRandomError, "RAND_bytes is not supported");
}
@@ -146,7 +144,7 @@ ossl_rand_pseudo_bytes(VALUE self, VALUE len)
int n = NUM2INT(len);
str = rb_str_new(0, n);
- if (!RAND_pseudo_bytes((unsigned char *)RSTRING_PTR(str), n)) {
+ if (RAND_pseudo_bytes((unsigned char *)RSTRING_PTR(str), n) < 1) {
ossl_raise(eRandomError, NULL);
}
@@ -165,7 +163,7 @@ ossl_rand_egd(VALUE self, VALUE filename)
{
SafeStringValue(filename);
- if(!RAND_egd(RSTRING_PTR(filename))) {
+ if (RAND_egd(RSTRING_PTR(filename)) == -1) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;
@@ -187,7 +185,7 @@ ossl_rand_egd_bytes(VALUE self, VALUE filename, VALUE len)
SafeStringValue(filename);
- if (!RAND_egd_bytes(RSTRING_PTR(filename), n)) {
+ if (RAND_egd_bytes(RSTRING_PTR(filename), n) == -1) {
ossl_raise(eRandomError, NULL);
}
return Qtrue;