Skip to content

web: validate the flag configuration in Serve and ServeMultiple - #439

Open
mrueg wants to merge 1 commit into
prometheus:masterfrom
mrueg:fix/serve-nil-flag-config
Open

web: validate the flag configuration in Serve and ServeMultiple#439
mrueg wants to merge 1 commit into
prometheus:masterfrom
mrueg:fix/serve-nil-flag-config

Conversation

@mrueg

@mrueg mrueg commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

ListenAndServe validates its FlagConfig before using it, but Serve and ServeMultiple go straight to dereferencing flags.WebConfigFile.

Both are exported for callers that create their own listeners, and such a caller builds a FlagConfig by hand rather than getting one from kingpinflag, so passing one without WebConfigFile set is an easy mistake. It crashes the process instead of returning ErrMissingFlag:

Serve(l, &http.Server{}, &FlagConfig{}, logger)
  → runtime error: invalid memory address or nil pointer dereference

Change

Check the flags in both, using a narrower check than checkFlags. The listener fields are deliberately not required here: the caller supplies the listener, so demanding a listen address or the systemd socket flag would reject a legitimate configuration. checkFlags keeps requiring them for ListenAndServe, which does create the listeners, and now shares the web-config half of the validation.

🤖 Generated with Claude Code

ListenAndServe validates its FlagConfig before using it, but Serve and
ServeMultiple went straight to dereferencing flags.WebConfigFile. Both are
exported for callers that create their own listeners, and such a caller
builds a FlagConfig by hand rather than getting one from kingpinflag, so
passing one without WebConfigFile set is an easy mistake. It crashed the
process with a nil pointer dereference instead of returning ErrMissingFlag.

Check the flags in both, using a narrower check than checkFlags. The
listener fields are deliberately not required here: the caller supplies the
listener, so demanding a listen address or the systemd socket flag would
reject a legitimate configuration. checkFlags keeps requiring them for
ListenAndServe, which does create the listeners itself, and now shares the
web config half of the validation.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
@mrueg
mrueg force-pushed the fix/serve-nil-flag-config branch from ad48efc to a236bc9 Compare September 2, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant