diff options
author | SHIBATA Hiroshi <hsbt@ruby-lang.org> | 2015-12-30 07:17:05 +0900 |
---|---|---|
committer | SHIBATA Hiroshi <hsbt@ruby-lang.org> | 2015-12-30 07:17:05 +0900 |
commit | 4862ab9e21a6962a96af2e6193f7889de61299c8 (patch) | |
tree | d942dce87ce04713cb9a65a5d2dc5974499d2927 /ext/openssl/ossl_rand.c | |
parent | 19b2ea9a5e5c8c21869665edcc6fd79622747b28 (diff) | |
download | ruby-openssl-4862ab9e21a6962a96af2e6193f7889de61299c8.tar.gz |
sync code from upstream
Diffstat (limited to 'ext/openssl/ossl_rand.c')
-rw-r--r-- | ext/openssl/ossl_rand.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/openssl/ossl_rand.c b/ext/openssl/ossl_rand.c index 018ef977..daf866d7 100644 --- a/ext/openssl/ossl_rand.c +++ b/ext/openssl/ossl_rand.c @@ -110,10 +110,16 @@ ossl_rand_bytes(VALUE self, VALUE len) { 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; |