web: fix nil pointer dereference when systemd socket activation is disabled - #435
Open
mrueg wants to merge 1 commit into
Open
web: fix nil pointer dereference when systemd socket activation is disabled#435mrueg wants to merge 1 commit into
mrueg wants to merge 1 commit into
Conversation
…sabled
checkFlags only required listen addresses to be set when WebSystemdSocket
was nil. A non-nil pointer to false satisfied the check, so a FlagConfig
with systemd socket activation explicitly disabled and no listen addresses
passed validation, and ListenAndServe then panicked dereferencing the nil
WebListenAddresses:
listeners := make([]net.Listener, 0, len(*flags.WebListenAddresses))
kingpinflag.AddFlags always returns a non-nil WebSystemdSocket pointer, so
this is reachable from any caller that builds a FlagConfig directly rather
than through the kingpin flags.
Require listen addresses whenever systemd socket activation is not actually
enabled, and add tests for checkFlags, which was previously uncovered.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
mrueg
force-pushed
the
fix/checkflags-nil-listen-addresses
branch
from
September 2, 2026 11:31
7f52774 to
0ac3bd0
Compare
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.
checkFlagsonly required listen addresses to be set whenWebSystemdSocketwasnil:A non-nil pointer to
falsesatisfies that condition, so aFlagConfigwith systemd socket activation explicitly disabled and no listen addresses passes validation.ListenAndServethen falls through to the port-listener path and panics dereferencing the nil pointer:kingpinflag.AddFlagsalways hands out a non-nilWebSystemdSocketpointer (it points atfalseon non-Linux), so this is reachable from any caller that builds aFlagConfigdirectly instead of going through the kingpin flags —FlagConfigis exported with documented fields, so that is a supported use.Fix: require listen addresses whenever systemd socket activation is not actually enabled.
checkFlags,ErrNoListenersandErrMissingFlaghad no test coverage at all, so this adds a table test forcheckFlagsplus an end-to-end check thatListenAndServereturnsErrNoListenersrather than panicking. Reverting the one-line fix makes the new tests fail with the nil dereference panic.