Skip to content

Commit 006b9e7

Browse files
committed
Tweak the existing special case for AIX in pg_getaddrinfo_all() to handle
yet another failure case in AIX's getaddrinfo(). Per report and patch by Andrew Chernow.
1 parent 4d65d28 commit 006b9e7

File tree

1 file changed

+18
-8
lines changed
  • src/backend/libpq

1 file changed

+18
-8
lines changed

src/backend/libpq/ip.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.43 2009/01/01 17:23:42 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/libpq/ip.c,v 1.44 2009/01/23 19:58:06 tgl Exp $
1212
*
1313
* This file and the IPV6 implementation were initially provided by
1414
* Nigel Kukard <nkukard@lbsd.net>, Linux Based Systems Design
@@ -74,36 +74,46 @@ pg_getaddrinfo_all(const char *hostname, const char *servname,
7474
return getaddrinfo_unix(servname, hintp, result);
7575
#endif
7676

77+
#ifndef _AIX
7778
/* NULL has special meaning to getaddrinfo(). */
7879
rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
7980
servname, hintp, result);
8081

81-
#ifdef _AIX
82+
#else /* _AIX */
8283

8384
/*
84-
* It seems some versions of AIX's getaddrinfo don't reliably zero
85-
* sin_port when servname is NULL, so clean up after it.
85+
* Various versions of AIX have various bugs in getaddrinfo()'s handling
86+
* of the servname parameter, including failing entirely if it's not NULL
87+
* and failing to zero sin_port when it is NULL :-(. Avoid these by
88+
* always passing NULL and handling the port number for ourselves.
8689
*/
87-
if (servname == NULL && rc == 0)
90+
rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
91+
NULL, hintp, result);
92+
93+
if (rc == 0)
8894
{
8995
struct addrinfo *addr;
96+
unsigned short port = 0;
97+
98+
if (servname && *servname)
99+
port = atoi(servname);
90100

91101
for (addr = *result; addr; addr = addr->ai_next)
92102
{
93103
switch (addr->ai_family)
94104
{
95105
case AF_INET:
96-
((struct sockaddr_in *) addr->ai_addr)->sin_port = htons(0);
106+
((struct sockaddr_in *) addr->ai_addr)->sin_port = htons(port);
97107
break;
98108
#ifdef HAVE_IPV6
99109
case AF_INET6:
100-
((struct sockaddr_in6 *) addr->ai_addr)->sin6_port = htons(0);
110+
((struct sockaddr_in6 *) addr->ai_addr)->sin6_port = htons(port);
101111
break;
102112
#endif
103113
}
104114
}
105115
}
106-
#endif
116+
#endif /* _AIX */
107117

108118
return rc;
109119
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy