-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix uint64->uint32 underflow issues resulting from using cosmoss…
…dk.io/math This fixes potential security issues resulting from extraneous parsing that used cosmossdk.math.ParseUint which uses math/big.Int which is a big integer package and can allow uint64 in places where uint32 is used and there were underflow checks. The fix for this change was to simply use strconv.ParseUint(s, 10, BIT_SIZE) where BIT_SIZE is any of 32 or 64 bits for uint32 and uint64 respectively, and by extracting the shared code to an internal package. Fixes #292
- Loading branch information
Showing
8 changed files
with
86 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/peggyjv/sommelier/internal | ||
|
||
go 1.23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
) | ||
|
||
// ParseUint64 parses s as a decimal uint64 value. | ||
func ParseUint64(s string) (uint64, error) { | ||
return strconv.ParseUint(s, 10, 64) | ||
} | ||
|
||
// ParseUint32 parses s as a decimal uint32 value. | ||
func ParseUint32(s string) (uint32, error) { | ||
// In response to https://github.com/PeggyJV/sommelier/issues/292 | ||
// let's use strconv.ParseUint to properly catch range errors and | ||
// avoid underflows. | ||
u, err := strconv.ParseUint(s, 10, 32) | ||
if err != nil { | ||
return 0, err | ||
} | ||
// Bullet-proof check to ensure no underflows (even though we already have range checks) | ||
u32 := uint32(u) | ||
if g := uint64(u32); g != u { | ||
return 0, fmt.Errorf("parseuint32 underflow detected: got %d, want %d", g, u) | ||
} | ||
return u32, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.