Skip to content

Fix null pointer dereference in LSP hover handler for undocumented IdentifierPath declarations#16782

Closed
Varunthaplyall wants to merge 1 commit into
argotorg:developfrom
Varunthaplyall:fix/lsp-hover-null-deref
Closed

Fix null pointer dereference in LSP hover handler for undocumented IdentifierPath declarations#16782
Varunthaplyall wants to merge 1 commit into
argotorg:developfrom
Varunthaplyall:fix/lsp-hover-null-deref

Conversation

@Varunthaplyall

Copy link
Copy Markdown

Description

Fixes #16766

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

Changes

  • libsolidity/lsp/DocumentHoverHandler.cpp: Added a null check on documentation() before accessing text(), matching the pattern already used for the sourceNode branch 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" (see libsolidity/ast/AST.h:497). The sibling branch (lines 108-109) correctly guards against this, but the IdentifierPath branch did not.

Testing

The existing LSP hover tests at test/libsolidity/lsp/hover/hover.sol continue 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.

…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
@clonker

clonker commented Jun 8, 2026

Copy link
Copy Markdown
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!

@clonker clonker closed this Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report on a solc LSP hover crash for undocumented IdentifierPath declarations

2 participants