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
This commit is contained in:
normal 2015-07-07 07:46:29 +00:00
Родитель bcd96d92f3
Коммит 50c0a20025
2 изменённых файлов: 7 добавлений и 2 удалений

Просмотреть файл

@ -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);
}