Skip to content

Commit

Permalink
evm_tokens: fix potential nil-pointer dereference
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Jun 6, 2023
1 parent f33b4a9 commit 2a42365
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions analyzer/evmtokens/evm_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (m Main) processStaleToken(ctx context.Context, batch *storage.QueryBatch,
// These two conditions should be equivalent; only a never-before-downloaded token
// can have a nil type, because downloading a token always sets the type.
// We check both just in case, because we later dereference the .Type pointer.
if staleToken.LastDownloadRound == nil || staleToken.Type == nil {
if staleToken.LastDownloadRound == nil || staleToken.Type == nil { //nolint:nestif // has complex nested blocks (complexity: 5)
tokenData, err := evm.EVMDownloadNewToken(
ctx,
m.logger,
Expand All @@ -112,14 +112,19 @@ func (m Main) processStaleToken(ctx context.Context, batch *storage.QueryBatch,
if err != nil {
return fmt.Errorf("downloading new token %s: %w", staleToken.Addr, err)
}
// If the returned token type is unsupported, it will have zero value token data.
var totalSupply *string
if tokenData.TotalSupply != nil {
totalSupply = common.Ptr(tokenData.TotalSupply.String())
}
batch.Queue(queries.RuntimeEVMTokenInsert,
m.runtime,
staleToken.Addr,
tokenData.Type,
tokenData.Name,
tokenData.Symbol,
tokenData.Decimals,
tokenData.TotalSupply.String(),
totalSupply,
)
} else if *staleToken.Type != evm.EVMTokenTypeUnsupported {
mutable, err := evm.EVMDownloadMutatedToken(
Expand Down

0 comments on commit 2a42365

Please sign in to comment.