ruby-changes:40731
From: kosaki <ko1@a...>
Date: Tue, 1 Dec 2015 05:29:13 +0900 (JST)
Subject: [ruby-changes:40731] kosaki:r52810 (trunk): * ext/openssl/ossl_rand.c (ossl_rand_bytes): RAND_bytes could
kosaki 2015-12-01 05:29:02 +0900 (Tue, 01 Dec 2015) New Revision: 52810 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52810 Log: * ext/openssl/ossl_rand.c (ossl_rand_bytes): RAND_bytes could be return -1 as an error. Therefore, added error handling. * ext/openssl/ossl_pkey_dsa.c (dsa_generate): ditto. Modified files: trunk/ChangeLog trunk/ext/openssl/ossl_pkey_dsa.c trunk/ext/openssl/ossl_rand.c Index: ChangeLog =================================================================== --- ChangeLog (revision 52809) +++ ChangeLog (revision 52810) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Oct 21 12:10:04 2015 KOSAKI Motohiro <kosaki.motohiro@g...> + + * ext/openssl/ossl_rand.c (ossl_rand_bytes): RAND_bytes could + be return -1 as an error. Therefore, added error handling. + * ext/openssl/ossl_pkey_dsa.c (dsa_generate): ditto. + Wed Oct 21 09:04:09 2015 KOSAKI Motohiro <kosaki.motohiro@g...> * include/ruby/util.h: remove a warning suppression C4723 Index: ext/openssl/ossl_pkey_dsa.c =================================================================== --- ext/openssl/ossl_pkey_dsa.c (revision 52809) +++ ext/openssl/ossl_pkey_dsa.c (revision 52810) @@ -110,7 +110,7 @@ dsa_generate(int size) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_dsa.c#L110 unsigned long h; if (!dsa) return 0; - if (!RAND_bytes(seed, seed_len)) { + if (RAND_bytes(seed, seed_len) <= 0) { DSA_free(dsa); return 0; } @@ -144,7 +144,7 @@ dsa_generate(int size) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_pkey_dsa.c#L144 int seed_len = 20, counter; unsigned long h; - if (!RAND_bytes(seed, seed_len)) { + if (RAND_bytes(seed, seed_len) <= 0) { return 0; } dsa = DSA_generate_parameters(size, seed, seed_len, &counter, &h, Index: ext/openssl/ossl_rand.c =================================================================== --- ext/openssl/ossl_rand.c (revision 52809) +++ ext/openssl/ossl_rand.c (revision 52810) @@ -110,10 +110,16 @@ ossl_rand_bytes(VALUE self, VALUE len) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_rand.c#L110 { VALUE str; int n = NUM2INT(len); + int ret; str = rb_str_new(0, n); - if (!RAND_bytes((unsigned char *)RSTRING_PTR(str), n)) { - ossl_raise(eRandomError, NULL); + 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); + } else if (ret == -1) { + ossl_raise(eRandomError, "RAND_bytes is not supported"); } return str; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/