* eval.c (rb_thread_atfork): When a ruby process forks, its random

seed shall be reinitialized to prevent CVE-2003-0900 situation.
  This bug affects for 1.8 and earlier series, but not for 1.9.
  fixed [ruby-core:34944].

* io.c (pipe_open): ditto.

* random.c (rb_reset_random_seed): ditto.

* intern.h (rb_reset_random_seed): ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@31655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
shyouhei 2011-05-20 21:21:39 +00:00
parent 408b181d2c
commit 793f30e38f
5 changed files with 23 additions and 1 deletions

View file

@ -1,3 +1,16 @@
Sat May 21 05:43:03 2011 URABE Shyouhei <shyouhei@ruby-lang.org>
* eval.c (rb_thread_atfork): When a ruby process forks, its random
seed shall be reinitialized to prevent CVE-2003-0900 situation.
This bug affects for 1.8 and earlier series, but not for 1.9.
fixed [ruby-core:34944].
* io.c (pipe_open): ditto.
* random.c (rb_reset_random_seed): ditto.
* intern.h (rb_reset_random_seed): ditto.
Sun May 15 21:43:09 2011 Akinori MUSHA <knu@iDaemons.org> Sun May 15 21:43:09 2011 Akinori MUSHA <knu@iDaemons.org>
* lib/uri/generic.rb (#route_from_path): Fix a bug where * lib/uri/generic.rb (#route_from_path): Fix a bug where

1
eval.c
View file

@ -13515,6 +13515,7 @@ rb_thread_atfork()
{ {
rb_thread_t th; rb_thread_t th;
rb_reset_random_seed();
if (rb_thread_alone()) return; if (rb_thread_alone()) return;
FOREACH_THREAD(th) { FOREACH_THREAD(th) {
if (th != curr_thread) { if (th != curr_thread) {

View file

@ -392,6 +392,7 @@ VALUE rb_length_by_each _((VALUE));
/* random.c */ /* random.c */
unsigned long rb_genrand_int32(void); unsigned long rb_genrand_int32(void);
double rb_genrand_real(void); double rb_genrand_real(void);
void rb_reset_random_seed(void);
/* re.c */ /* re.c */
int rb_memcmp _((const void*,const void*,long)); int rb_memcmp _((const void*,const void*,long));
int rb_memcicmp _((const void*,const void*,long)); int rb_memcicmp _((const void*,const void*,long));

1
io.c
View file

@ -3274,6 +3274,7 @@ retry:
rb_thread_stop_timer(); rb_thread_stop_timer();
switch ((pid = fork())) { switch ((pid = fork())) {
case 0: /* child */ case 0: /* child */
rb_thread_atfork();
if (modef & FMODE_READABLE) { if (modef & FMODE_READABLE) {
close(pr[0]); close(pr[0]);
if (pr[1] != 1) { if (pr[1] != 1) {

View file

@ -488,9 +488,15 @@ rb_f_rand(argc, argv, obj)
} }
void void
Init_Random() rb_reset_random_seed()
{ {
rand_init(random_seed()); rand_init(random_seed());
}
void
Init_Random()
{
rb_reset_random_seed();
rb_define_global_function("srand", rb_f_srand, -1); rb_define_global_function("srand", rb_f_srand, -1);
rb_define_global_function("rand", rb_f_rand, -1); rb_define_global_function("rand", rb_f_rand, -1);
rb_global_variable(&saved_seed); rb_global_variable(&saved_seed);