lightningd/peer_control: initialize error pointer in handle_peer_spoke#9001
Open
ThomsenDrake wants to merge 1 commit intoElementsProject:masterfrom
Open
lightningd/peer_control: initialize error pointer in handle_peer_spoke#9001ThomsenDrake wants to merge 1 commit intoElementsProject:masterfrom
ThomsenDrake wants to merge 1 commit intoElementsProject:masterfrom
Conversation
The local variable `error` in handle_peer_spoke() is declared as a pointer type with no initialization. Several error paths jump to the `send_error` label where `error` is dereferenced (passed to tal_hex() and towire_connectd_peer_send_msg()). While sockpair() currently sets the `error` pointer via the output parameter on failure, the declaration should be initialized to NULL as a defensive measure and to avoid undefined behavior if code paths change. Fixes ElementsProject#8849
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.
Summary
Fixes #8849
The Bug
In
lightningd/peer_control.c, thehandle_peer_spoke()function declares a local pointer variableerrorwithout initialization:Several error paths jump to the
send_errorlabel whereerroris dereferenced — specifically passed total_hex(tmpctx, error)andtowire_connectd_peer_send_msg(). Iferroris not initialized before reachingsend_error, this is undefined behavior (likely a segfault).The affected
goto send_errorpaths are all onsockpair()failure:While
sockpair()currently does set theerrorpointer via its output parameter on failure, the uninitialized declaration is still undefined behavior and fragile against future code changes.The Fix
Initialize
errortoNULLat declaration:This is the minimal, defensive fix that prevents undefined behavior regardless of which path reaches
send_error.