Fix null pointer dereference in LSP hover handler for undocumented IdentifierPath declarations#16782
Closed
Varunthaplyall wants to merge 1 commit into
Closed
Conversation
…entifierPath declarations The IdentifierPath branch in DocumentHoverHandler calls structurallyDocumented->documentation()->text() without first checking whether documentation() returns nullptr. When a declaration referenced through an IdentifierPath (e.g., inheritance specifier, modifier invocation, override specifier, using directive) has no NatSpec documentation, this causes a segfault (exit code 139). Fix adds a null check on documentation() before accessing text(), matching the pattern already used for the sourceNode branch on line 108. Fixes argotorg#16766
Member
|
LSP is unmaintained, deprecated, and will be removed soon. Fixing anything here doesn't get us anywhere. In that sense, deleting LSP from the codebase is the proper fix for the issue you linked. Still, thank you for the interest and contribution! |
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.
Description
Fixes #16766
The
IdentifierPathbranch inDocumentHoverHandlercallsstructurallyDocumented->documentation()->text()without first checking whetherdocumentation()returnsnullptr. When a declaration referenced through anIdentifierPath(e.g., inheritance specifier, modifier invocation, override specifier, using directive) has no NatSpec documentation, this causes a segfault (exit code 139).Changes
libsolidity/lsp/DocumentHoverHandler.cpp: Added a null check ondocumentation()before accessingtext(), matching the pattern already used for thesourceNodebranch on line 108 of the same file.Root cause
The
StructurallyDocumented::documentation()method explicitly documents that it "Can contain a nullptr in which case indicates absence of documentation" (seelibsolidity/ast/AST.h:497). The sibling branch (lines 108-109) correctly guards against this, but theIdentifierPathbranch did not.Testing
The existing LSP hover tests at
test/libsolidity/lsp/hover/hover.solcontinue to pass. No new tests needed as the fix simply applies the same null-check pattern already present in the same function.Risk
Minimal. This is a one-line addition that mirrors existing code in the same function.