From: Brad Fitzpatrick Date: Tue, 22 Nov 2016 01:40:07 +0000 (+0000) Subject: time: make Parse validate day's lower bound in addition to upper bound X-Git-Tag: go1.8beta1~75 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=323b5c9d37e3633c96a96303da71b5d45cc9bac6;p=gostls13.git time: make Parse validate day's lower bound in addition to upper bound Day 0 is as invalid as day 32. Fixes #17874 Change-Id: I52109d12bafd6d957d00c44d540cb88389fff0a7 Reviewed-on: https://go-review.googlesource.com/33429 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/time/format.go b/src/time/format.go index 3608b04e44..3fbfa734d0 100644 --- a/src/time/format.go +++ b/src/time/format.go @@ -1012,7 +1012,7 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error) } // Validate the day of the month. - if day > daysIn(Month(month), year) { + if day < 1 || day > daysIn(Month(month), year) { return Time{}, &ParseError{alayout, avalue, "", value, ": day out of range"} } diff --git a/src/time/format_test.go b/src/time/format_test.go index 640e8180e3..aa4434a09c 100644 --- a/src/time/format_test.go +++ b/src/time/format_test.go @@ -224,6 +224,7 @@ var dayOutOfRangeTests = []struct { {"Thu Nov 31 21:00:57 2010", false}, {"Thu Dec 31 21:00:57 2010", true}, {"Thu Dec 32 21:00:57 2010", false}, + {"Thu Dec 00 21:00:57 2010", false}, } func TestParseDayOutOfRange(t *testing.T) {