-
Notifications
You must be signed in to change notification settings - Fork 39
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
Fix Segmentation Fault in UnauthenticatedTenRPCCall in audit #2243
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, but I have a question
@@ -64,18 +64,24 @@ func UnauthenticatedTenRPCCall[R any](ctx context.Context, w *services.Services, | |||
|
|||
res, err := cache.WithCache(w.RPCResponsesCache, cfg, generateCacheKey(cacheArgs), func() (*R, error) { | |||
return services.WithPlainRPCConnection(ctx, w.BackendRPC, func(client *rpc.Client) (*R, error) { | |||
var resp *R | |||
var resp R |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember the reason why it had to be a pointer.
I'm wondering if we were to make this back a pointer and leave the if
at the end, would it still seg-fault?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't remember why *R was used here.
After some research I think we can keep *R and do explicit allocation var resp *R = new(R)
as it protects us from nil
pointer dereference.
What do you think? Should I switch back to *R?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes please. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Why this change is needed
A segmentation fault was occurring during the audit function call while formatting RPC call results (res) and errors (err).
More details: https://github.com/ten-protocol/ten-internal/issues/4479
What changes were made as part of this PR
Please provide a high level list of the changes made
PR checks pre-merging
Please indicate below by ticking the checkbox that you have read and performed the required
PR checks