ruby-changes:64819
From: Nobuyoshi <ko1@a...>
Date: Sun, 10 Jan 2021 21:34:45 +0900 (JST)
Subject: [ruby-changes:64819] c63552eab1 (master): Remove possibility of using same seeds
https://git.ruby-lang.org/ruby.git/commit/?id=c63552eab1 From c63552eab1a13c6c05e18d763c7acf3c4c5383ed Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 10 Jan 2021 21:29:07 +0900 Subject: Remove possibility of using same seeds diff --git a/random.c b/random.c index 29491fa..4b5965f 100644 --- a/random.c +++ b/random.c @@ -583,7 +583,7 @@ ruby_fill_random_bytes(void *seed, size_t size, int need_secure) https://github.com/ruby/ruby/blob/trunk/random.c#L583 static void fill_random_seed(uint32_t *seed, size_t cnt) { - static int n = 0; + static rb_atomic_t n = 0; #if defined HAVE_CLOCK_GETTIME struct timespec tv; #elif defined HAVE_GETTIMEOFDAY @@ -606,7 +606,7 @@ fill_random_seed(uint32_t *seed, size_t cnt) https://github.com/ruby/ruby/blob/trunk/random.c#L606 #if SIZEOF_TIME_T > SIZEOF_INT seed[0] ^= (uint32_t)((time_t)tv.tv_sec >> SIZEOF_INT * CHAR_BIT); #endif - seed[2] ^= getpid() ^ (n++ << 16); + seed[2] ^= getpid() ^ (ATOMIC_FETCH_ADD(n, 1) << 16); seed[3] ^= (uint32_t)(VALUE)&seed; #if SIZEOF_VOIDP > SIZEOF_INT seed[2] ^= (uint32_t)((VALUE)&seed >> SIZEOF_INT * CHAR_BIT); -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/