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

p2p/discover/v5wire: fix nil dereference on handshakeAuthData #30861

Closed

Conversation

marcello33
Copy link

This PR fixes a nil pointer dereference in the decodeHandshakeMessage.
There's an improper handling of the auth variable returned by the decodeHandshake function when an error occurs.
The function decodeHandshakeMessage does not validate if auth is nil before dereferencing it.
Upstreaming this from Polygon PoS bor client PR.

Wrt the implementation, the check if auth != nil can be considered pleonastic next to auth.isHandshakeAuthDataValid(), but I decided to keep it to avoid static analysis tools (often integrated into IDEs) to scream about possible nil pointer dereferences, and would keep the code safe even when isHandshakeAuthDataValid is modified.

@fjl fjl changed the title fix: nil dereference on handshakeAuthData p2p/discover/v5wire: fix nil dereference on handshakeAuthData Dec 6, 2024
@fjl
Copy link
Contributor

fjl commented Dec 6, 2024

I don't fully understand your change. On master branch, the function decodeHandshakeAuthData does not return auth as a pointer, so it is not susceptible to nil dereference.

Your PR makes it return a pointer, and then you add a nil check to prevent the issue.

Can you please tell which issue you are actually trying to fix here?

@marcello33 marcello33 closed this Dec 7, 2024
@marcello33
Copy link
Author

Right, I was looking at the accessed fields, but those are zero values and not nil. Thank you

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

Successfully merging this pull request may close these issues.

2 participants