diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-16 19:46:08 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-06-16 19:46:08 +0000 |
commit | f45d127ada4fd0f3d64788c13d5f3e0b27ba7062 (patch) | |
tree | 692c86005f878585529d92e099fa367314ae80e4 | |
parent | 98d45ef140dcc53f4dd7c0dbdd25433d5c378ff7 (diff) |
* 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
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | time.c | 22 |
2 files changed, 25 insertions, 1 deletions
@@ -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, @@ -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 |