From: Adam Langley Date: Mon, 10 Mar 2014 16:33:45 +0000 (-0400) Subject: time: handle int64 overflow in ParseDuration. X-Git-Tag: go1.3beta1~409 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4ca6e588e4bac8bffa56dfe42526d7a12e7cb69c;p=gostls13.git 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 --- diff --git a/src/pkg/time/format.go b/src/pkg/time/format.go index 6f92c12626..b9da7ba42a 100644 --- a/src/pkg/time/format.go +++ b/src/pkg/time/format.go @@ -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 } diff --git a/src/pkg/time/time_test.go b/src/pkg/time/time_test.go index 2615517d9a..4ae7da5a44 100644 --- a/src/pkg/time/time_test.go +++ b/src/pkg/time/time_test.go @@ -842,6 +842,7 @@ var parseDurationTests = []struct { {"-.", false, 0}, {".s", false, 0}, {"+.s", false, 0}, + {"3000000h", false, 0}, // overflow } func TestParseDuration(t *testing.T) {