Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE in getAccountInfo() if result is nil #45

Open
riptl opened this issue Mar 6, 2022 · 5 comments
Open

NPE in getAccountInfo() if result is nil #45

riptl opened this issue Mar 6, 2022 · 5 comments

Comments

@riptl
Copy link
Contributor

riptl commented Mar 6, 2022

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).

err = cl.rpcClient.CallForInto(ctx, &out, "getAccountInfo", params)
if err != nil {
return nil, err
}
if out.Value == nil {

Ideally the RPC client would never panic under any circumstances

@gagliardetto
Copy link
Owner

How about

if out == nil || out.Value == nil { 

but in that case, can we be sure that out == nil means not found ?

@riptl
Copy link
Contributor Author

riptl commented Mar 8, 2022

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.

@gagliardetto
Copy link
Owner

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 )

@gagliardetto
Copy link
Owner

gagliardetto commented Mar 8, 2022

if out == nil {
   return nil, errors.New("expected a value, got null response")
}

@gagliardetto
Copy link
Owner

e6a5806

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants