1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* time.c (rb_time_new): prevent overflow by "* 1000".

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2011-06-16 19:46:08 +00:00
parent 98d45ef140
commit f45d127ada
2 changed files with 25 additions and 1 deletions

View file

@ -1,3 +1,7 @@
Thu Jun 16 14:32:31 2011 NARUSE, Yui <naruse@ruby-lang.org>
* time.c (rb_time_new): prevent overflow by "* 1000".
Fri Jun 17 03:07:36 2011 Koichi Sasada <ko1@atdot.net>
* benchmark/bm_vm4_thread_create_join.rb,

22
time.c
View file

@ -2299,7 +2299,27 @@ time_new_timew(VALUE klass, wideval_t timew)
VALUE
rb_time_new(time_t sec, long usec)
{
return time_new_timew(rb_cTime, nsec2timew(sec, usec * 1000));
wideval_t timew;
if (usec >= 1000000) {
long sec2 = usec / 1000000;
if (sec > TIMET_MAX - sec2) {
rb_raise(rb_eRangeError, "out of Time range");
}
usec -= sec2 * 1000000;
sec += sec2;
}
else if (usec <= 1000000) {
long sec2 = usec / 1000000;
if (sec < -TIMET_MAX - sec2) {
rb_raise(rb_eRangeError, "out of Time range");
}
usec -= sec2 * 1000000;
sec += sec2;
}
timew = nsec2timew(sec, usec * 1000);
return time_new_timew(rb_cTime, timew);
}
VALUE