From dbf74f4abf69bd4539c7b2652c9adb82c189107b Mon Sep 17 00:00:00 2001 From: Kesha Antonov Date: Sun, 31 May 2026 08:50:14 +0300 Subject: [PATCH] fix(api): guard nil AccountID in getAdditionalInfoStonfi 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. --- pkg/api/emulation.go | 5 ++++- pkg/api/emulation_stonfi_nil_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 pkg/api/emulation_stonfi_nil_test.go diff --git a/pkg/api/emulation.go b/pkg/api/emulation.go index b15f7256..337ca7f0 100644 --- a/pkg/api/emulation.go +++ b/pkg/api/emulation.go @@ -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{ @@ -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) } } diff --git a/pkg/api/emulation_stonfi_nil_test.go b/pkg/api/emulation_stonfi_nil_test.go new file mode 100644 index 00000000..27f9ae8b --- /dev/null +++ b/pkg/api/emulation_stonfi_nil_test.go @@ -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) + } +}