Skip to content

Commit e64efc7

Browse files
committed
internal: cap expires_in to MaxInt32
Fixes #279 Change-Id: I29914e7995ec334a7474390a0ba96fe61deba6bb Reviewed-on: https://go-review.googlesource.com/c/161962 Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ross Light <[email protected]>
1 parent 529b322 commit e64efc7

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

internal/token.go

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"io"
1313
"io/ioutil"
14+
"math"
1415
"mime"
1516
"net/http"
1617
"net/url"
@@ -90,6 +91,9 @@ func (e *expirationTime) UnmarshalJSON(b []byte) error {
9091
if err != nil {
9192
return err
9293
}
94+
if i > math.MaxInt32 {
95+
i = math.MaxInt32
96+
}
9397
*e = expirationTime(i)
9498
return nil
9599
}

internal/token_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ package internal
66

77
import (
88
"context"
9+
"fmt"
910
"io"
11+
"math"
1012
"net/http"
1113
"net/http/httptest"
1214
"net/url"
@@ -62,3 +64,14 @@ func TestRetrieveTokenWithContexts(t *testing.T) {
6264
t.Errorf("RetrieveToken (with cancelled context) = nil; want error")
6365
}
6466
}
67+
68+
func TestExpiresInUpperBound(t *testing.T) {
69+
var e expirationTime
70+
if err := e.UnmarshalJSON([]byte(fmt.Sprint(int64(math.MaxInt32) + 1))); err != nil {
71+
t.Fatal(err)
72+
}
73+
const want = math.MaxInt32
74+
if e != want {
75+
t.Errorf("expiration time = %v; want %v", e, want)
76+
}
77+
}

0 commit comments

Comments
 (0)