fix: guard against nil profile in CALL_RESULT parsing#413
Open
rishabhvaish wants to merge 1 commit intolorenzodonini:masterfrom
Open
fix: guard against nil profile in CALL_RESULT parsing#413rishabhvaish wants to merge 1 commit intolorenzodonini:masterfrom
rishabhvaish wants to merge 1 commit intolorenzodonini:masterfrom
Conversation
The CALL_RESULT handler in ParseMessage called GetProfileForFeature without checking the ok return value, causing a nil pointer panic when the profile lookup fails. The CALL handler already had the correct guard. Added the same check for CALL_RESULT responses and a test for the new error path. Closes lorenzodonini#313
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The CALL_RESULT handler in ParseMessage calls GetProfileForFeature on line 464 but discards the ok return value:
goprofile, _ := endpoint.GetProfileForFeature(request.GetFeatureName())
If the profile lookup fails, profile is nil and the immediate profile.ParseResponse(...) call panics with a nil pointer dereference. This can happen when a charge point responds with a CallResult for a feature whose profile isn't registered on the receiving endpoint.
The CALL handler already has the correct guard (line 439-441), so I've added the same check for the CALL_RESULT path. When no profile is found, it now returns an InternalError instead of crashing. Also added a test for this error path.
Fixes #313