[前][次][番号順一覧][スレッド一覧]

ruby-changes:43058

From: rhe <ko1@a...>
Date: Mon, 23 May 2016 19:47:42 +0900 (JST)
Subject: [ruby-changes:43058] rhe:r55132 (trunk): openssl: fix incorrect return value check of RAND_* functions

rhe	2016-05-23 19:47:37 +0900 (Mon, 23 May 2016)

  New Revision: 55132

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55132

  Log:
    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@m...>
      [ruby-core:63795] [Bug #10053]
      (ossl_pseudo_bytes): Similar, RAND_pseudo_bytes() may return 0 or
      -1 on failure.

  Modified files:
    trunk/ChangeLog
    trunk/ext/openssl/ossl_rand.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55131)
+++ ChangeLog	(revision 55132)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon May 23 19:41:27 2016  Kazuki Yamaguchi  <k@r...>
+
+	* 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@m...>
+	  [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@r...>
 
 	* ext/bigdecimal/bigdecimal.c (isfinite): isfinite does not always
Index: ext/openssl/ossl_rand.c
===================================================================
--- ext/openssl/ossl_rand.c	(revision 55131)
+++ ext/openssl/ossl_rand.c	(revision 55132)
@@ -114,10 +114,8 @@ ossl_rand_bytes(VALUE self, VALUE len) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_rand.c#L114
 
     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 https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_rand.c#L144
     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 https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_rand.c#L163
 {
     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 fi https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_rand.c#L185
 
     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;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]