Skip to content

Commit 967978e

Browse files
authored
fix: guard txsubmission server against int overflows (#898)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent d99f377 commit 967978e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

protocol/txsubmission/server.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@ package txsubmission
1616

1717
import (
1818
"fmt"
19+
"math"
1920
"sync"
2021

2122
"github.com/blinklabs-io/gouroboros/ledger/common"
@@ -93,7 +94,18 @@ func (s *Server) RequestTxIds(
9394
"role", "server",
9495
"connection_id", s.callbackContext.ConnectionId.String(),
9596
)
96-
msg := NewMsgRequestTxIds(blocking, uint16(s.ackCount), uint16(reqCount))
97+
var ack, req uint16
98+
if s.ackCount > 0 && s.ackCount <= math.MaxUint16 {
99+
ack = uint16(s.ackCount)
100+
} else if s.ackCount > math.MaxUint16 {
101+
ack = math.MaxUint16
102+
}
103+
if reqCount > 0 && reqCount <= math.MaxUint16 {
104+
req = uint16(reqCount)
105+
} else if reqCount > math.MaxUint16 {
106+
req = math.MaxUint16
107+
}
108+
msg := NewMsgRequestTxIds(blocking, ack, req)
97109
if err := s.SendMessage(msg); err != nil {
98110
return nil, err
99111
}

0 commit comments

Comments
 (0)