summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-03 12:23:58 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-03 12:23:58 +0000
commit970ce1fd0987f4a4943f38a32a010f01940d78d6 (patch)
tree01a76e90ac09e83141184ee5fee1fbc3f5e90d9a /lib
parent909a92ea6ddf476411c580c8e075dfd078a59ddc (diff)
merges r32050 from trunk into ruby_1_9_2.
-- * lib/securerandom.rb (SecureRandom.random_bytes): modify PRNG state to prevent random number sequence repeatation at forked child process which has same pid. reported by Eric Wong. [ruby-core:35765] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@32381 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/securerandom.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/securerandom.rb b/lib/securerandom.rb
index 1c88a61fd7..5f8f69836d 100644
--- a/lib/securerandom.rb
+++ b/lib/securerandom.rb
@@ -57,6 +57,14 @@ module SecureRandom
n ||= 16
if defined? OpenSSL::Random
+ @pid = $$ if !defined?(@pid)
+ pid = $$
+ if @pid != pid
+ now = Time.now
+ ary = [now.to_i, now.nsec, @pid, pid]
+ OpenSSL::Random.seed(ary.to_s)
+ @pid = pid
+ end
return OpenSSL::Random.random_bytes(n)
end