solana-go
solana-go copied to clipboard
NPE in getAccountInfo() if result is nil
If a non-compliant RPC server returns result: null
for getAccountInfo(), the client will panic with null pointer deref (line 127 on out.Value
because out
is nil
).
https://github.com/gagliardetto/solana-go/blob/dd0af958252d8cdd28db04a39fc67103223946cc/rpc/getAccountInfo.go#L123-L127
Ideally the RPC client would never panic under any circumstances
How about
if out == nil || out.Value == nil {
but in that case, can we be sure that out == nil
means not found
?
imo, out == nil
violates the spec, so it's best to error here instead of assuming a valid result. Maybe we could wrap CallForInto
to return an error if out == nil
after unmarshaling.
In some cases, result == nil
follows the spec (e.g. getBlock
: https://github.com/solana-labs/solana/blob/master/docs/src/developing/clients/jsonrpc-api.md#getblock )
if out == nil {
return nil, errors.New("expected a value, got null response")
}
https://github.com/gagliardetto/solana-go/commit/e6a58061889f44feecf7e5e6305cc851d06fb3a5