Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/api/emulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func EmulatedTreeToTrace(
func getAdditionalInfoStonfi(ctx context.Context, sharedExecutor *shardsAccountExecutor, additionalInfo *core.TraceAdditionalInfo, token0, token1 tlb.MsgAddress) {
t0, err0 := ton.AccountIDFromTlb(token0)
t1, err1 := ton.AccountIDFromTlb(token1)
if err1 != nil || err0 != nil {
if err1 != nil || err0 != nil || t0 == nil || t1 == nil {
return
}
additionalInfo.STONfiPool = &core.STONfiPool{
Expand All @@ -461,6 +461,9 @@ func getAdditionalInfoStonfi(ctx context.Context, sharedExecutor *shardsAccountE
}
data := value.(abi.GetWalletDataResult)
master, _ := ton.AccountIDFromTlb(data.Jetton)
if master == nil {
continue
}
additionalInfo.SetJettonMaster(accountID, *master)
}
}
26 changes: 26 additions & 0 deletions pkg/api/emulation_stonfi_nil_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package api

import (
"context"
"testing"

"github.com/tonkeeper/opentonapi/pkg/core"
"github.com/tonkeeper/tongo/tlb"
)

// TestStonfiNilAddressNoPanic is the regression test for the getAdditionalInfoStonfi
// nil-pointer dereference: ton.AccountIDFromTlb returns (nil, nil) for addr_none /
// addr_extern, so a STONfi pool reporting an addr_none token address used to panic
// the serving goroutine. After the guard, the function returns gracefully without
// setting STONfiPool. (On the unpatched code this test panics.)
func TestStonfiNilAddressNoPanic(t *testing.T) {
none := tlb.MsgAddress{SumType: "AddrNone"}
info := &core.TraceAdditionalInfo{}

// must not panic on addr_none token addresses
getAdditionalInfoStonfi(context.Background(), nil, info, none, none)

if info.STONfiPool != nil {
t.Fatalf("expected STONfiPool to be unset when token addresses are addr_none, got %+v", info.STONfiPool)
}
}