summaryrefslogtreecommitdiff
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
commit427d707b5d1256a13f4eb2b7f1ad326484ee82e1 (patch)
treed4003e85852e1acbf7257fdfaf05168a45e77cc6
parentb2e133abd2d3c9626076a99fce0d6966b95e975f (diff)
* 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_8@32050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--lib/securerandom.rb8
2 files changed, 15 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 482350ce09..59e0743c5e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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]
+
Thu Jun 9 20:30:00 2011 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date.rb: zone_to_diff in this version is just class method.
diff --git a/lib/securerandom.rb b/lib/securerandom.rb
index 2676c3b536..ab1997dfa4 100644
--- a/lib/securerandom.rb
+++ b/lib/securerandom.rb
@@ -50,6 +50,14 @@ module SecureRandom
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.usec, @pid, pid]
+ OpenSSL::Random.seed(ary.to_s)
+ @pid = pid
+ end
return OpenSSL::Random.random_bytes(n)
end
if !defined?(@has_urandom) || @has_urandom