Skip to content

Commit

Permalink
Validate tm values before timegm(); close #3368
Browse files Browse the repository at this point in the history
This issue was reported by https://hackerone.com/volc
  • Loading branch information
matz committed Jan 9, 2017
1 parent d3a8ebf commit c4491e4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mrbgems/mruby-time/src/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday,
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_RUNTIME_ERROR, "argument out of range");

if (timezone == MRB_TIMEZONE_UTC) {
nowsecs = timegm(&nowtime);
}
Expand Down

0 comments on commit c4491e4

Please sign in to comment.