Skip to content

Commit

Permalink
fix: incorrect conversion between integer types (#49)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
wolf31o2 and github-advanced-security[bot] authored Jan 26, 2025
1 parent 2fb8e8f commit af22a31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions serialization/HDWallet/HDWallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (hd *HDWallet) DerivePath(path string) (*HDWallet, error) {
derived_wallet := hd.copy()
for _, index := range strings.Split(strings.TrimLeft(path, "m/"), "/") {
if strings.HasSuffix(index, "'") {
ind_val, err := strconv.Atoi(string(index[:len(index)-1]))
ind_val, err := strconv.ParseUint(string(index[:len(index)-1]), 10, 32)

if err != nil {
return nil, err
Expand All @@ -167,7 +167,7 @@ func (hd *HDWallet) DerivePath(path string) (*HDWallet, error) {
uint32(ind_val), true,
)
} else {
ind_val, err := strconv.Atoi(index)
ind_val, err := strconv.ParseUint(index, 10, 32)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func (hd *HDWallet) Derive(index uint32, hardened bool) *HDWallet {
return &HDWallet{
RootXprivKey: hd.RootXprivKey,
XPrivKey: derived_xprivkey,
Path: hd.Path + "/" + strconv.Itoa(int(index)),
Path: hd.Path + "/" + strconv.FormatUint(uint64(index), 10),
Seed: hd.Seed,
Mnemonic: hd.Mnemonic,
Passphrase: hd.Passphrase,
Expand Down
4 changes: 4 additions & 0 deletions serialization/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package serialization
import (
"encoding/hex"
"fmt"
"math"
"reflect"
"strconv"

Expand Down Expand Up @@ -116,6 +117,9 @@ func (cb *CustomBytes) Int() (int, error) {
if err != nil {
return 0, err
}
if value < math.MinInt || value > math.MaxInt {
return 0, fmt.Errorf("value out of int range")
}
return int(value), nil
}
return 0, fmt.Errorf("not int")
Expand Down

0 comments on commit af22a31

Please sign in to comment.