diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-04-19 13:49:44 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-04-19 15:49:50 +0900 |
| commit | 049ec9056ee728587c0f43e2e923c83f621c40b4 (patch) | |
| tree | 681f33d5c0cab111497f74a5f853b4f80a87eb46 | |
| parent | 713fb53bbf593bdcfec128aa2238977efe22ebfb (diff) | |
| download | mruby-049ec9056ee728587c0f43e2e923c83f621c40b4.tar.gz mruby-049ec9056ee728587c0f43e2e923c83f621c40b4.zip | |
time.c: add integer boundary check for year.
On configurations where `sizeof(mrb_int) > sizeof(int)`.
| -rw-r--r-- | mrbgems/mruby-time/src/time.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 907e3fcd2..22dec2e65 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -461,22 +461,29 @@ time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday, time_t nowsecs; struct tm nowtime = { 0 }; - nowtime.tm_year = (int)ayear - 1900; - nowtime.tm_mon = (int)amonth - 1; +#if MRB_INT_MAX > INT_MAX +#define OUTINT(x) (INT_MIN > (x) || (x) > INT_MAX) +#else +#define OUTINT(x) 0 +#endif + + if (OUTINT(ayear-1900) || + amonth < 1 || amonth > 12 || + aday < 1 || aday > 31 || + ahour < 0 || ahour > 24 || + (ahour == 24 && (amin > 0 || asec > 0)) || + amin < 0 || amin > 59 || + asec < 0 || asec > 60) + mrb_raise(mrb, E_ARGUMENT_ERROR, "argument out of range"); + + nowtime.tm_year = (int)(ayear - 1900); + nowtime.tm_mon = (int)(amonth - 1); nowtime.tm_mday = (int)aday; nowtime.tm_hour = (int)ahour; nowtime.tm_min = (int)amin; nowtime.tm_sec = (int)asec; nowtime.tm_isdst = -1; - if (nowtime.tm_mon < 0 || nowtime.tm_mon > 11 - || nowtime.tm_mday < 1 || nowtime.tm_mday > 31 - || nowtime.tm_hour < 0 || nowtime.tm_hour > 24 - || (nowtime.tm_hour == 24 && (nowtime.tm_min > 0 || nowtime.tm_sec > 0)) - || nowtime.tm_min < 0 || nowtime.tm_min > 59 - || nowtime.tm_sec < 0 || nowtime.tm_sec > 60) - mrb_raise(mrb, E_ARGUMENT_ERROR, "argument out of range"); - if (timezone == MRB_TIMEZONE_UTC) { nowsecs = timegm(&nowtime); } |
