Skip to content

Commit

Permalink
fix(client/tx): avoid integer uint64->int64 overflow by big.Int conve…
Browse files Browse the repository at this point in the history
…rsion

Avoids a potential uint64->int64 overflow when creating math.LegacyDec,
instead opting to use big.Int.SetUint64(x)

Fixes https://github.com/cosmos/cosmos-sdk/security/code-scanning/9412
  • Loading branch information
odeke-em committed Dec 4, 2023
1 parent e049998 commit 8b328ba
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (client) [#18622](https://github.com/cosmos/cosmos-sdk/pull/18622) Fixed a potential under/overflow from `uint64->int64` when computing gas fees as a LegacyDec.
* (client/keys) [#18562](https://github.com/cosmos/cosmos-sdk/pull/18562) `keys delete` won't terminate when a key is not found
* (server) [#18537](https://github.com/cosmos/cosmos-sdk/pull/18537) Fix panic when defining minimum gas config as `100stake;100uatom`. Use a `,` delimiter instead of `;`. Fixes the server config getter to use the correct delimiter.
* [#18531](https://github.com/cosmos/cosmos-sdk/pull/18531) Baseapp's `GetConsensusParams` returns an empty struct instead of panicking if no params are found.
Expand Down
4 changes: 3 additions & 1 deletion client/tx/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ func (f Factory) BuildUnsignedTx(msgs ...sdk.Msg) (client.TxBuilder, error) {
return nil, errors.New("cannot provide both fees and gas prices")
}

glDec := math.LegacyNewDec(int64(f.gas))
// f.gas is a uint64 and we should convert to LegacyDec
// without the risk of under/overflow via uint64->int64.
glDec := math.LegacyNewDecFromBigInt(new(big.Int).SetUint64(f.gas))

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: big) (typecheck)

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: big) (typecheck)

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: big) (typecheck)

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: big) (typecheck)

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: big (typecheck)

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: big

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: big

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: big

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: big

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: big

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: big

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: big

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: big

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: big

Check failure on line 316 in client/tx/factory.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: big

// Derive the fees based on the provided gas prices, where
// fee = ceil(gasPrice * gasLimit).
Expand Down

0 comments on commit 8b328ba

Please sign in to comment.