aboutsummaryrefslogtreecommitdiffstats
path: root/lib/securerandom.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-13 09:36:48 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-13 09:36:48 +0000
commit58bae71a7b023b5bb5fdcfefb46232f3f14bc519 (patch)
tree3cc9cb8fedf5c909d56ddeacc344987c3a15e200 /lib/securerandom.rb
parentdf366010177157228cb11d2cd6050bc32044df8f (diff)
downloadruby-58bae71a7b023b5bb5fdcfefb46232f3f14bc519.tar.gz
* 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/trunk@32050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/securerandom.rb')
-rw-r--r--lib/securerandom.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/securerandom.rb b/lib/securerandom.rb
index e04251bb67..d238a35406 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