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

* time.c (time_overflow_p): Avoid signed integer overflow.

(rb_time_new): Fix overflow condition.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42447 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-08-08 12:59:21 +00:00
parent 685597fdc1
commit fef170e87c
2 changed files with 9 additions and 8 deletions

View file

@ -1,6 +1,7 @@
Thu Aug 8 21:32:22 2013 Tanaka Akira <akr@fsij.org>
Thu Aug 8 21:56:44 2013 Tanaka Akira <akr@fsij.org>
* time.c (time_overflow_p): Avoid signed integer overflow.
(rb_time_new): Fix overflow condition.
Thu Aug 8 19:58:02 2013 Koichi Sasada <ko1@atdot.net>

14
time.c
View file

@ -2226,16 +2226,16 @@ time_overflow_p(time_t *secp, long *nsecp)
if (TIMET_MAX - sec2 < sec) {
rb_raise(rb_eRangeError, "out of Time range");
}
nsec %= 1000000000;
nsec -= sec2 * 1000000000;
sec += sec2;
}
if (nsec < 0) { /* nsec negative overflow */
else if (nsec < 0) { /* nsec negative overflow */
sec2 = NDIV(nsec,1000000000); /* negative div */
if (sec < TIMET_MIN - sec2) {
rb_raise(rb_eRangeError, "out of Time range");
}
nsec = NMOD(nsec,1000000000); /* negative mod */
sec = sec + sec2;
nsec -= sec2 * 1000000000;
sec += sec2;
}
#ifndef NEGATIVE_TIME_T
if (sec < 0)
@ -2281,9 +2281,9 @@ rb_time_new(time_t sec, long usec)
usec -= sec2 * 1000000;
sec += sec2;
}
else if (usec <= 1000000) {
long sec2 = usec / 1000000;
if (sec < -TIMET_MAX - sec2) {
else if (usec < 0) {
long sec2 = NDIV(usec,1000000); /* negative div */
if (sec < TIMET_MIN - sec2) {
rb_raise(rb_eRangeError, "out of Time range");
}
usec -= sec2 * 1000000;