diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-07 07:46:29 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-07-07 07:46:29 +0000 |
commit | 50c0a20025bafd9c608fa7d92ef282c0cbdc2c9c (patch) | |
tree | 53f18913cb1b023cabee62a1aa42465da91db3cc | |
parent | bcd96d92f3239aff3152afe8ff4e72f3aa2ea287 (diff) | |
download | ruby-50c0a20025bafd9c608fa7d92ef282c0cbdc2c9c.tar.gz |
random.c: fix failures on old Linux
This follows the behavior of fill_random_bytes_urandom and fixes
the following failures I encountered on my old machine:
1) Error:
TestSecureRandom#test_s_random_bytes_without_openssl:
NotImplementedError: No random device
$RUBYDIR/lib/securerandom.rb:66:in `gen_random'
$RUBYDIR/lib/securerandom.rb:94:in `random_bytes'
$RUBYDIR/test/test_securerandom.rb:12:in `test_s_random_bytes'
$RUBYDIR/test/test_securerandom.rb:97:in `block in test_s_random_bytes_without_openssl'
$RUBYDIR/lib/tmpdir.rb:88:in `mktmpdir'
$RUBYDIR/test/test_securerandom.rb:85:in `test_s_random_bytes_without_openssl'
2) Error:
TestSecureRandom#test_s_urlsafe_base64:
NotImplementedError: No random device
$RUBYDIR/lib/securerandom.rb:66:in `gen_random'
$RUBYDIR/lib/securerandom.rb:94:in `random_bytes'
$RUBYDIR/lib/securerandom.rb:164:in `urlsafe_base64'
$RUBYDIR/test/test_securerandom.rb:131:in `block in test_s_urlsafe_base64'
$RUBYDIR/test/test_securerandom.rb:130:in `times'
$RUBYDIR/test/test_securerandom.rb:130:in `test_s_urlsafe_base64'
3) Error:
TestSecureRandom#test_uuid:
NotImplementedError: No random device
$RUBYDIR/lib/securerandom.rb:66:in `gen_random'
$RUBYDIR/lib/securerandom.rb:94:in `random_bytes'
$RUBYDIR/lib/securerandom.rb:230:in `uuid'
$RUBYDIR/test/test_securerandom.rb:160:in `test_uuid'
* random.c (fill_random_bytes_syscall): return -1 for error
* random.c (fill_random_bytes): try urandom on syscall failure
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | random.c | 4 |
2 files changed, 7 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Tue Jul 7 16:39:04 2015 Eric Wong <e@80x24.org> + + * random.c (fill_random_bytes_syscall): return -1 for error + * random.c (fill_random_bytes): try urandom on syscall failure + Tue Jul 7 15:02:18 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> * file.c (rb_str_normalize_ospath): skip invalid byte sequence not @@ -529,7 +529,7 @@ fill_random_bytes_syscall(void *seed, size_t size) } if ((size_t)ret == size) return 0; } - return 0; + return -1; } #else # define fill_random_bytes_syscall(seed, size) -1 @@ -539,7 +539,7 @@ static int fill_random_bytes(void *seed, size_t size) { int ret = fill_random_bytes_syscall(seed, size); - if (ret) return ret; + if (ret == 0) return ret; return fill_random_bytes_urandom(seed, size); } |