fix(api): guard nil AccountID in getAdditionalInfoStonfi (panic on addr_none pool tokens)#886
Open
kesha-antonov wants to merge 1 commit into
Open
fix(api): guard nil AccountID in getAdditionalInfoStonfi (panic on addr_none pool tokens)#886kesha-antonov wants to merge 1 commit into
kesha-antonov wants to merge 1 commit into
Conversation
ton.AccountIDFromTlb returns (nil, nil) for AddrNone/AddrExtern, but getAdditionalInfoStonfi only checked the error before dereferencing the returned pointer. A STONfi pool reporting an addr_none token address therefore panicked the serving goroutine. Add the nil-pointer guards, mirroring the existing check in the NFT/jetton branch, plus a regression test.
Contributor
|
lgtm |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
getAdditionalInfoStonfi(pkg/api/emulation.go) panics with a nil-pointerdereference when a STONfi pool's
get_pool_datareturns a token address ofaddr_none(oraddr_extern).ton.AccountIDFromTlbreturns(nil, nil)- a nil pointer and a nil error -for
AddrNone/AddrExtern, but the function only checks the error beforedereferencing the returned pointer:
So emulating any trace that inspects such a contract panics the serving goroutine.
Why it's a clear bug, not an invariant
The NFT/jetton branch in the same function already guards exactly this pattern:
getAdditionalInfoStonfisimply omits the check on its three dereference sites.Fix
Add the nil-pointer guards, mirroring the existing sibling branch (return early if
either token resolves to a nil
AccountID; skip the jetton-master deref if itdoes). One line per site, no behavior change for valid addresses.
Test
Adds
TestStonfiNilAddressNoPanic(inpkg/api/): callsgetAdditionalInfoStonfiwith
addr_nonetoken addresses and asserts it returns without panicking andleaves
STONfiPoolunset. The test panics on the current code and passes with thefix.
Reproduction (before the fix)
A
get_pool_data(method id 81689) returning a STONfi-shaped stack whoseToken0Address/Token1Addressslices hold the 2-bitaddr_noneprefix decodescleanly via
abi.DecodeGetPoolData_StonfiResultand then panics ingetAdditionalInfoStonfi:runtime error: invalid memory address or nil pointer dereferenceatemulation.go:454.