Skip to content

Commit 92c3e5c

Browse files
authored
fix: guard era number int overflow (#359)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 424b29d commit 92c3e5c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

internal/api/localstatequery.go

Lines changed: 12 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 api
1616

1717
import (
1818
"encoding/hex"
19+
"math"
1920

2021
"github.com/blinklabs-io/gouroboros/ledger"
2122
"github.com/gin-gonic/gin"
@@ -77,8 +78,13 @@ func handleLocalStateQueryCurrentEra(c *gin.Context) {
7778
return
7879
}
7980

80-
// Create response
81+
if eraNum < 0 || eraNum > math.MaxUint8 {
82+
c.JSON(500, apiError("era number int overflow"))
83+
return
84+
}
8185
era := ledger.GetEraById(uint8(eraNum))
86+
87+
// Create response
8288
resp := responseLocalStateQueryCurrentEra{
8389
Id: era.Id,
8490
Name: era.Name,
@@ -182,6 +188,10 @@ func handleLocalStateQueryTip(c *gin.Context) {
182188
c.JSON(500, apiError(err.Error()))
183189
return
184190
}
191+
if eraNum < 0 || eraNum > math.MaxUint8 {
192+
c.JSON(500, apiError("era number int overflow"))
193+
return
194+
}
185195
era := ledger.GetEraById(uint8(eraNum))
186196

187197
// Get epochNo

0 commit comments

Comments
 (0)