diff --git a/ChangeLog b/ChangeLog index b22845f95b..9fae94249e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Sat May 21 05:43:03 2011 URABE Shyouhei + + * 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 * lib/uri/generic.rb (#route_from_path): Fix a bug where diff --git a/eval.c b/eval.c index a54fdce6b9..222a868b53 100644 --- a/eval.c +++ b/eval.c @@ -13515,6 +13515,7 @@ rb_thread_atfork() { rb_thread_t th; + rb_reset_random_seed(); if (rb_thread_alone()) return; FOREACH_THREAD(th) { if (th != curr_thread) { diff --git a/intern.h b/intern.h index 927cdf2ea2..321fb4cc18 100644 --- a/intern.h +++ b/intern.h @@ -392,6 +392,7 @@ VALUE rb_length_by_each _((VALUE)); /* random.c */ unsigned long rb_genrand_int32(void); double rb_genrand_real(void); +void rb_reset_random_seed(void); /* re.c */ int rb_memcmp _((const void*,const void*,long)); int rb_memcicmp _((const void*,const void*,long)); diff --git a/io.c b/io.c index f7f17c85fb..d40e570860 100644 --- a/io.c +++ b/io.c @@ -3274,6 +3274,7 @@ retry: rb_thread_stop_timer(); switch ((pid = fork())) { case 0: /* child */ + rb_thread_atfork(); if (modef & FMODE_READABLE) { close(pr[0]); if (pr[1] != 1) { diff --git a/random.c b/random.c index 92ef3fcae5..45a94d0563 100644 --- a/random.c +++ b/random.c @@ -488,9 +488,15 @@ rb_f_rand(argc, argv, obj) } void -Init_Random() +rb_reset_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("rand", rb_f_rand, -1); rb_global_variable(&saved_seed);