Skip to content

NULL Pointer Dereference in handleMsgLockCoin() #8

@Jdkhnjggf

Description

@Jdkhnjggf

Describe The Bug

The lock of an unregistered coin leads to a null pointer dereference of the asset handler located at /x/asset/handler.go. Specifically, the handleMsgLockCoin() routine is designed to handle the MsgLockCoin message in order to lock a coin. However, the checks on the input message are not thorough. As a result, a malicious MsgLockCoin message can be crafted to contain an unregistered coin and its execution could lead to a null pointer dereference of the running processes. In the following, we show the related code snippet.

Code Snippets (Optional)

165	// handleMsgLockCoin Handle Msg lock coin
166	func handleMsgLockCoin(ctx chainTypes.Context, k keeper.AssetCoinsKeeper, msg *types.MsgLockCoin) (*sdk.Result, error) {
	    ... ...
181	    for _, c := range msgData.Amount {
182	        creator, symbol, err := chainTypes.CoinAccountsFromDenom(c.Denom)
183		if err != nil {
184		    return nil, sdkerrors.Wrapf(err, "get creator and symbol from coin %s", msg.Amount.String())
185		}
186
187		stat, err := k.GetCoinStat(ctx.Context(), creator, symbol)
188		if err != nil {
189		    return nil, sdkerrors.Wrapf(err, "get coin stat from coin %s", msg.Amount.String())
190		}
191
192		if !stat.CanLock {
193		    return nil, sdkerrors.Wrapf(types.ErrAssetCoinCannotBeLock, "coin %s cannot be locked", msg.Amount.String())
194		}
195	    }

Input/Output

  1. Craft a MsgLockCoin: '{"id": "kratos", "amount": "1kratos/kvs", "height": "111"}'
  2. Output: '{"panic": "runtime error: invalid memory address or nil pointer dereference"}'

To Reproduce
Steps to reproduce the behavior:

  1. sudo ./scripts/boot-testnet.sh
  2. sudo ./build/ktscli tx asset lock kratos 111 1kratos/kvs --keyring-backend test --chain-id testing --home /testing/cli/ --from kratos

Expected Behavior

Returns an error "coin stat is nil".

Screenshots

lock-screenshot

Desktop (please complete the following information):

  • OS: [macOS High Sierra 10.13.6]

Additional Context (Optional)

None

Contact Information

Email - [email protected]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions