Skip to content

fix: guard RemoteAddr parsing against out-of-bounds slice panic#2463

Open
iliaal wants to merge 1 commit into
php:mainfrom
iliaal:fix/remote-addr-panic-cgo-crash
Open

fix: guard RemoteAddr parsing against out-of-bounds slice panic#2463
iliaal wants to merge 1 commit into
php:mainfrom
iliaal:fix/remote-addr-panic-cgo-crash

Conversation

@iliaal
Copy link
Copy Markdown

@iliaal iliaal commented Jun 4, 2026

addKnownVariablesToServer stripped IPv6 brackets with an unchecked slice, so a malformed RemoteAddr like "[" or "[:9000" panicked. This runs in the go_register_server_variables cgo callback, where a panic can't cross the C frame and crashes the whole process. Not reachable behind stock Caddy; reachable for library callers and real-IP rewrites.

Fix: parse via net.SplitHostPort with a bounds-safe fallback. TestSplitRemoteAddr covers the crashing inputs; well-formed addresses are unchanged.

addKnownVariablesToServer stripped IPv6 brackets with an unchecked
slice (ip[1:len(ip)-1]). A malformed RemoteAddr such as "[" or
"[:9000" produced a 1-byte ip and panicked. This runs inside the
go_register_server_variables cgo callback, where a Go panic cannot
unwind through the C frame and aborts the whole process rather than
failing a single request.

Extract splitRemoteAddr, which parses via net.SplitHostPort and falls
back to a bounds-safe lenient split that only strips brackets when both
are present. Behavior for well-formed addresses is unchanged.
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.

3 participants