Skip to content

Commit

Permalink
* lib/securerandom.rb (SecureRandom.random_bytes): modify PRNG state
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
akr committed Jun 13, 2011
1 parent df36601 commit 58bae71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Mon Jun 13 18:33:04 2011 Tanaka Akira <akr@fsij.org>

* 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]

Mon Jun 13 17:02:34 2011 NARUSE, Yui <naruse@ruby-lang.org>

* lib/net/http.rb (Net::HTTP#use_ssl?): require 'openssl' only when
Expand Down
8 changes: 8 additions & 0 deletions lib/securerandom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ def self.random_bytes(n=nil)
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

Expand Down

0 comments on commit 58bae71

Please sign in to comment.