Issue #6990 has been reported by h.shirosaki (Hiroshi Shirosaki).

----------------------------------------
Bug #6990: test_s_random_bytes_without_openssl error on Windows x64
https://bugs.ruby-lang.org/issues/6990

Author: h.shirosaki (Hiroshi Shirosaki)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 2.0.0dev (2012-09-06 trunk 36917) [x64-mingw32]


=begin

TestSecureRandom sometimes has an error on ci.rubyinstaller.

http://ci.rubyinstaller.org/job/ruby-trunk-x64-test-all/41/console


 3) Error:
 test_s_random_bytes_without_openssl(TestSecureRandom):
 SystemCallError: unknown error - CryptGenRandom failed: The parameter is incorrect.
 C:/Users/Worker/Jenkins/workspace/ruby-trunk-x64-build/lib/securerandom.rb:116:in `random_bytes'
 C:/Users/Worker/Jenkins/workspace/ruby-trunk-x64-build/test/test_securerandom.rb:12:in `test_s_random_bytes'
 C:/Users/Worker/Jenkins/workspace/ruby-trunk-x64-build/test/test_securerandom.rb:97:in `block in test_s_random_bytes_without_openssl'
 C:/Users/Worker/Jenkins/workspace/ruby-trunk-x64-build/lib/tmpdir.rb:88:in `mktmpdir'
 C:/Users/Worker/Jenkins/workspace/ruby-trunk-x64-build/test/test_securerandom.rb:85:in `test_s_random_bytes_without_openssl'
 

This error seems to occur only on x64.

I guess the following scenario.

Pointer size of @hProv seems limited to 32bit with x64 ruby.
If the pointer value was larger than 32bit max, it would fail.

https://github.com/ruby/ruby/blob/trunk/lib/securerandom.rb#L106

I don't get the error at test-all on my local box, but I can get same error with the following script.
It takes long time to get the error.


 require "openssl"
 OpenSSL.send(:remove_const, :Random)
 require "securerandom"
 
 i = 0
 loop do
   SecureRandom.random_bytes
   SecureRandom.send(:remove_instance_variable, :@has_win32)
   p SecureRandom.send(:instance_variable_get, :@hProv).to_s(16) if (i % 10000) == 0
   i += 1
 end


I attached a patch. I also fixed encoding error which occurs if error message contains Japanese characters.

=end


-- 
http://bugs.ruby-lang.org/