1
0
mirror of https://github.com/golang/go synced 2024-11-23 07:50:05 -07:00

time: handle int64 overflow in ParseDuration.

Previously, passing a long duration to ParseDuration could result in
random, even negative, values.

LGTM=r
R=golang-codereviews, bradfitz, r
CC=golang-codereviews
https://golang.org/cl/72120043
This commit is contained in:
Adam Langley 2014-03-10 12:33:45 -04:00
parent 4bc632cead
commit 4ca6e588e4
2 changed files with 4 additions and 0 deletions

View File

@ -1240,5 +1240,8 @@ func ParseDuration(s string) (Duration, error) {
if neg {
f = -f
}
if f < float64(-1<<63) || f > float64(1<<63-1) {
return 0, errors.New("time: overflow parsing duration")
}
return Duration(f), nil
}

View File

@ -842,6 +842,7 @@ var parseDurationTests = []struct {
{"-.", false, 0},
{".s", false, 0},
{"+.s", false, 0},
{"3000000h", false, 0}, // overflow
}
func TestParseDuration(t *testing.T) {