Fix access violation in initialize when client omits optional clientInfo fields - #168
Open
dickbonnema wants to merge 1 commit into
Open
dickbonnema wants to merge 1 commit into
dickbonnema wants to merge 1 commit into
Conversation
TOptionalString/TOptionalInteger are classes that stay nil when the client omits the field. Dereferencing them in ShowConfigStatus (Params.clientInfo.version.HasValue) and TDiagnostic.Assign (Src.source.HasValue) caused an access violation during initialize for clients that send clientInfo without a version (or no clientInfo). Guard both derefs with Assigned() checks. Verified end-to-end against lazarus-mcp LSP smoke tests (5/5 passing with full capabilities).
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.
Problem
Commit 818f633 (#159) changed
TClientInfo.versionfromstringtoTOptionalString, andTDiagnostic.code/sourcetoTOptionalInteger/TOptionalString. TheseTOptional*types are classes that staynilwhen the client omits the field from the JSON payload.Two dereference sites were not nil-safe:
TInitialize.ShowConfigStatus(src/serverprotocol/PasLS.General.pas):Params.clientInfo.version.HasValueraises an access violation duringinitializewhen the client sendsclientInfowithout aversion(or noclientInfoat all - both are optional per the LSP spec). The server responds with{"error":{"code":-32603,"message":"Access violation"}}and cannot be used.TDiagnostic.Assign(src/protocol/LSP.Basic.pas):Src.source.HasValuehas the same issue whensourcewas never set.Reproduction
Send an
initializerequest withclientInfopresent but withoutversion:{"jsonrpc":"2.0","id":1,"method":"initialize","params":{ "processId": 1234, "clientInfo": {"name": "my-client"}, "rootUri": "file:///tmp/x", "capabilities": {} }}? Server replies
-32603 Access violationon trunk (818f633).Fix
Guard both dereferences with
Assigned()checks. No behaviour change for clients that do send the fields.Verified end-to-end: with this patch, the full LSP handshake (initialize ? didOpen ? hover ? definition ? publishDiagnostics ? shutdown) completes successfully against a client that omits
clientInfo.version.