summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2015-06-17 09:19:09 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2015-06-17 09:19:09 +0900
commit6a796cb4ccd53a35c93c89c1074d556186207966 (patch)
tree13df65c25a076b25468f7e8de085fe36e39bb5df
parent6dcc3e7383907efc07e6d7e1abc968deecdb914d (diff)
downloadmruby-6a796cb4ccd53a35c93c89c1074d556186207966.tar.gz
mruby-6a796cb4ccd53a35c93c89c1074d556186207966.zip
Added a check for 64 bit time_t overflow; based on a patch from @kext; close #2836
-rw-r--r--mrbgems/mruby-time/src/time.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c
index da3451d22..081e84c1c 100644
--- a/mrbgems/mruby-time/src/time.c
+++ b/mrbgems/mruby-time/src/time.c
@@ -201,11 +201,14 @@ time_alloc(mrb_state *mrb, double sec, double usec, enum mrb_timezone timezone)
struct mrb_time *tm;
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)) {
+ if (sizeof(time_t) == 8 && (sec > (double)INT64_MAX || (double)INT64_MIN > sec)) {
+ goto out_of_range;
+ }
+ tm->sec = (time_t)sec;
+ 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));
}