]> Cypherpunks.ru repositories - gostls13.git/commitdiff
time: fix Parse for empty seconds
authorJoe Tsai <joetsai@digital-static.net>
Sun, 21 Aug 2022 09:21:49 +0000 (02:21 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 23 Aug 2022 17:35:01 +0000 (17:35 +0000)
The error return value of the seconds field is overwritten
and not checked in the presence of a fractional second.
Perform an explicit check for errors.

Fixes #54569

Change-Id: I1204c8bdcd5a5a09b773d9e44748141ed1e5cb20
Reviewed-on: https://go-review.googlesource.com/c/go/+/425036
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Rob Pike <r@golang.org>
src/time/format.go
src/time/format_test.go

index ed2a0a8fc683e45a12ea8de7fbc1393f74a57555..a278cd9e6b8f909178676408d5952f85e56a4cd3 100644 (file)
@@ -1135,6 +1135,9 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
                        }
                case stdSecond, stdZeroSecond:
                        sec, value, err = getnum(value, std == stdZeroSecond)
+                       if err != nil {
+                               break
+                       }
                        if sec < 0 || 60 <= sec {
                                rangeErrString = "second"
                                break
index 0e5b92440e4ca0fa0856f80822bd642cccff7e12..e8caa5e1a47970cc2cfa776638b42f7a366eeef5 100644 (file)
@@ -591,6 +591,8 @@ var parseErrorTests = []ParseErrorTest{
        {RFC3339, "2006-01-02T15:04:05Z_abc", `parsing time "2006-01-02T15:04:05Z_abc": extra text: "_abc"`},
        // invalid second followed by optional fractional seconds
        {RFC3339, "2010-02-04T21:00:67.012345678-08:00", "second out of range"},
+       // issue 54569
+       {RFC3339, "0000-01-01T00:00:.0+00:00", `parsing time "0000-01-01T00:00:.0+00:00" as "2006-01-02T15:04:05Z07:00": cannot parse ".0+00:00" as "05"`},
        // issue 21113
        {"_2 Jan 06 15:04 MST", "4 --- 00 00:00 GMT", "cannot parse"},
        {"_2 January 06 15:04 MST", "4 --- 00 00:00 GMT", "cannot parse"},