summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-time
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-07-02 10:28:10 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-07-02 10:28:10 +0900
commite749267909f879ac3e8b8cf681c2c6067d056a96 (patch)
treea0cef70058af161c92309000ed72843bd19b9693 /mrbgems/mruby-time
parentad50277549dc751ddabaa04c5c48749015e5e14a (diff)
downloadmruby-e749267909f879ac3e8b8cf681c2c6067d056a96.tar.gz
mruby-e749267909f879ac3e8b8cf681c2c6067d056a96.zip
time overflow check; ref #2337
Diffstat (limited to 'mrbgems/mruby-time')
-rw-r--r--mrbgems/mruby-time/src/time.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c
index 410b36173..d111ca29c 100644
--- a/mrbgems/mruby-time/src/time.c
+++ b/mrbgems/mruby-time/src/time.c
@@ -201,6 +201,13 @@ time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone)
tm = (struct mrb_time *)mrb_malloc(mrb, sizeof(struct mrb_time));
tm->sec = (time_t)sec;
+ if (sizeof(time_t) == 4 && (sec > (double)INT32_MAX || (double)INT32_MIN > sec)) {
+ goto out_of_range;
+ }
+ else if ((sec > 0 && tm->sec < 0) || (sec < 0 && (double)tm->sec > sec)) {
+ out_of_range:
+ mrb_raisef(mrb, E_ARGUMENT_ERROR, "%S out of Time range", mrb_float_value(mrb, sec));
+ }
tm->usec = (time_t)((sec - tm->sec) * 1.0e6 + usec);
while (tm->usec < 0) {
tm->sec--;