summaryrefslogtreecommitdiff
path: root/random.c
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-07 07:46:29 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-07 07:46:29 +0000
commit50c0a20025bafd9c608fa7d92ef282c0cbdc2c9c (patch)
tree53f18913cb1b023cabee62a1aa42465da91db3cc /random.c
parentbcd96d92f3239aff3152afe8ff4e72f3aa2ea287 (diff)
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
Diffstat (limited to 'random.c')
-rw-r--r--random.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/random.c b/random.c
index 853c287040..b66f5cbe4e 100644
--- a/random.c
+++ b/random.c
@@ -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);
}