Skip to content

Commit 0044b40

Browse files
guggerojamaljsr
authored andcommitted
session: fix uint64 overflow for dates in far future
This commit fixes an overflow that was caused by serializing the default date the UI sends (Jan 1st, 9999) to unix nanoseconds.
1 parent 9b84dbc commit 0044b40

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

session/tlv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func SerializeSession(w io.Writer, session *Session) error {
3535
label = []byte(session.Label)
3636
state = uint8(session.State)
3737
typ = uint8(session.Type)
38-
expiry = uint64(session.Expiry.UnixNano())
38+
expiry = uint64(session.Expiry.Unix())
3939
serverAddr = []byte(session.ServerAddr)
4040
devServer = uint8(0)
4141
pairingSecret = session.PairingSecret[:]
@@ -128,7 +128,7 @@ func DeserializeSession(r io.Reader) (*Session, error) {
128128
session.Label = string(label)
129129
session.State = State(state)
130130
session.Type = Type(typ)
131-
session.Expiry = time.Unix(0, int64(expiry))
131+
session.Expiry = time.Unix(int64(expiry), 0)
132132
session.ServerAddr = string(serverAddr)
133133
session.DevServer = devServer == 1
134134

session/tlv_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func TestSerializeDeserializeSession(t *testing.T) {
3333
mac := createDummyMacaroon(t)
3434

3535
session, err := NewSession(
36-
"this is a session", TypeMacaroonCustom, time.Now(),
36+
"this is a session", TypeMacaroonCustom,
37+
time.Date(99999, 1, 1, 0, 0, 0, 0, time.UTC),
3738
"foo.bar.baz:1234", true,
3839
)
3940
require.NoError(t, err)
@@ -52,8 +53,7 @@ func TestSerializeDeserializeSession(t *testing.T) {
5253
// a struct. So we need to compare the timestamp itself and then make
5354
// sure the rest of the session is equal separately.
5455
require.Equal(
55-
t, session.Expiry.UnixNano(),
56-
deserializedSession.Expiry.UnixNano(),
56+
t, session.Expiry.Unix(), deserializedSession.Expiry.Unix(),
5757
)
5858
session.Expiry = time.Time{}
5959
deserializedSession.Expiry = time.Time{}

0 commit comments

Comments
 (0)