-
Notifications
You must be signed in to change notification settings - Fork 245
Fix IPv6 crash: drop dead HAVE_IPV6 guards left after PG16 merge - #1946
Fix IPv6 crash: drop dead HAVE_IPV6 guards left after PG16 merge #1946leborchuk wants to merge 1 commit into
Conversation
Upstream PostgreSQL commit "Remove configure probe for sockaddr_in6 and require AF_INET6." (bcc8b14) deleted the HAVE_IPV6 probe and stripped the #ifdef HAVE_IPV6 guards from its own code, since AF_INET6 is now always available. Cloudberry-specific code still gated IPv6 handling behind #ifdef HAVE_IPV6, so after the PG16 merge those blocks became dead code: HAVE_IPV6 is never defined on non-Windows builds. The practical effect: on an IPv6-only cluster, getDnsCachedAddress() never populates its cache entry (the IPv6 branch was compiled out), then returns e->hostinfo with e == NULL -- a bogus non-NULL pointer (offsetof key[]) -- which the caller passes to pstrdup(), crashing in strlen(). This shows up as a coordinator/FtsProbe SIGSEGV: #0 __strlen_evex #1 MemoryContextStrdup #2 getCdbComponentInfo apache#3 cdbcomponent_getCdbComponents apache#4 FtsProbeMain Remove the leftover #ifdef HAVE_IPV6 guards so the IPv6 paths compile unconditionally, matching what upstream did to its own files. Also guard the cache return against a NULL entry so an unresolvable segment logs a clean "cannot resolve network address" error instead of segfaulting. Files: cdbutil.c (both getDnsCachedAddress copies), auth.c, and the interconnect listener setup (ic_common.c, ic_tcp.c, ic_udpifc.c). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 Approval recommended
The changes correctly remove dead IPv6 guards and the updated getDnsCachedAddress() behavior is handled by existing callers (NULL-checked) to prevent the reported crash.
Pull request overview
This PR fixes a crash in IPv6-only deployments introduced after the PostgreSQL 16 merge by removing dead HAVE_IPV6 compilation guards (now that AF_INET6 is always available) and preventing getDnsCachedAddress() from returning an invalid non-NULL pointer when the cache entry was never populated.
Changes:
- Remove leftover
#ifdef HAVE_IPV6guards so IPv6 code paths compile unconditionally (matching upstream PG16 behavior). - Make
getDnsCachedAddress(..., use_cache=true)returnNULLwhen no cache entry was created, avoiding invalid pointer returns and subsequent segfaults. - Unconditionally enable IPv6-aware formatting / address-family preference logic in interconnect listener setup and socket address formatting.
File summaries
| File | Description |
|---|---|
| src/backend/libpq/auth.c | Removes dead HAVE_IPV6 guard so AF_INET6 connections are handled consistently in internal auth checks. |
| src/backend/cdb/cdbutil.c | Un-gates IPv6 lookup logic and prevents invalid cache-pointer returns by returning NULL when no entry exists. |
| contrib/interconnect/udp/ic_udpifc.c | Removes dead HAVE_IPV6 guard around AF_INET/AF_INET6 preference logic for UDP listeners. |
| contrib/interconnect/tcp/ic_tcp.c | Removes dead HAVE_IPV6 guard around AF_INET/AF_INET6 preference logic for TCP listeners. |
| contrib/interconnect/ic_common.c | Removes dead HAVE_IPV6 guard so IPv6 addresses are always bracket-formatted. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
@yjhjstz
yjhjstz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Upstream PostgreSQL commit "Remove configure probe for sockaddr_in6 and require AF_INET6." (bcc8b14) deleted the HAVE_IPV6 probe and stripped the #ifdef HAVE_IPV6 guards from its own code, since AF_INET6 is now always available. Cloudberry-specific code still gated IPv6 handling behind #ifdef HAVE_IPV6, so after the PG16 merge those blocks became dead code: HAVE_IPV6 is never defined on non-Windows builds.
The practical effect: on an IPv6-only cluster, getDnsCachedAddress() never populates its cache entry (the IPv6 branch was compiled out), then returns e->hostinfo with e == NULL -- a bogus non-NULL pointer (offsetof key[]) -- which the caller passes to pstrdup(), crashing in strlen(). This shows up as a coordinator/FtsProbe SIGSEGV:
#0 __strlen_evex
#1 MemoryContextStrdup
#2 getCdbComponentInfo
#3 cdbcomponent_getCdbComponents
#4 FtsProbeMain
Remove the leftover #ifdef HAVE_IPV6 guards so the IPv6 paths compile unconditionally, matching what upstream did to its own files. Also guard the cache return against a NULL entry so an unresolvable segment logs a clean "cannot resolve network address" error instead of segfaulting.
Files: cdbutil.c (both getDnsCachedAddress copies), auth.c, and the interconnect listener setup (ic_common.c, ic_tcp.c, ic_udpifc.c).