1
- // Copyright 2024 Blink Labs Software
1
+ // Copyright 2025 Blink Labs Software
2
2
//
3
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
4
// you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@ package localtxmonitor
17
17
import (
18
18
"encoding/hex"
19
19
"fmt"
20
+ "math"
20
21
21
22
"github.com/blinklabs-io/gouroboros/ledger"
22
23
"github.com/blinklabs-io/gouroboros/protocol"
@@ -193,6 +194,9 @@ func (s *Server) handleNextTx() error {
193
194
return nil
194
195
}
195
196
mempoolTx := s .mempoolTxs [s .mempoolNextTxIdx ]
197
+ if mempoolTx .EraId > math .MaxUint8 {
198
+ return fmt .Errorf ("integer overflow in era id" )
199
+ }
196
200
newMsg := NewMsgReplyNextTx (uint8 (mempoolTx .EraId ), mempoolTx .Tx )
197
201
if err := s .SendMessage (newMsg ); err != nil {
198
202
return err
@@ -213,10 +217,18 @@ func (s *Server) handleGetSizes() error {
213
217
for _ , tx := range s .mempoolTxs {
214
218
totalTxSize += len (tx .Tx )
215
219
}
220
+ numTxs := len (s .mempoolTxs )
221
+ // check for over/underflows
222
+ if totalTxSize < 0 || totalTxSize > math .MaxUint32 {
223
+ return fmt .Errorf ("integrer overflow in total tx size" )
224
+ }
225
+ if numTxs < 0 || numTxs > math .MaxUint32 {
226
+ return fmt .Errorf ("integrer overflow in tx count" )
227
+ }
216
228
newMsg := NewMsgReplyGetSizes (
217
229
s .mempoolCapacity ,
218
- uint32 (totalTxSize ),
219
- uint32 (len ( s . mempoolTxs ) ),
230
+ uint32 (totalTxSize ), // #nosec G115
231
+ uint32 (numTxs ),
220
232
)
221
233
if err := s .SendMessage (newMsg ); err != nil {
222
234
return err
0 commit comments