Skip to content

Commit fed19f3

Browse files
committed
Don't connect() to a wildcard address in test_postmaster_connection().
At least OpenBSD, NetBSD, and Windows don't support it. This repairs pg_ctl for listen_addresses='0.0.0.0' and listen_addresses='::'. Since pg_ctl prefers to test a Unix-domain socket, Windows users are most likely to need this change. Back-patch to 9.1 (all supported versions). This could change pg_ctl interaction with loopback-interface firewall rules. Therefore, in 9.4 and earlier (released branches), activate the change only on known-affected platforms. Reported (bug #13611) and designed by Kondo Yuta.
1 parent fba60e5 commit fed19f3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/bin/pg_ctl/pg_ctl.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,20 @@ test_postmaster_connection(pgpid_t pm_pid, bool do_checkpoint)
646646
return PQPING_NO_ATTEMPT;
647647
}
648648

649-
/* If postmaster is listening on "*", use localhost */
649+
/*
650+
* Map listen-only addresses to counterparts usable
651+
* for establishing a connection. connect() to "::"
652+
* or "0.0.0.0" is not portable to OpenBSD 5.0 or to
653+
* Windows Server 2008, and connect() to "::" is
654+
* additionally not portable to NetBSD 6.0. (Cygwin
655+
* does handle both addresses, though.)
656+
*/
650657
if (strcmp(host_str, "*") == 0)
651658
strcpy(host_str, "localhost");
659+
else if (strcmp(host_str, "0.0.0.0") == 0)
660+
strcpy(host_str, "127.0.0.1");
661+
else if (strcmp(host_str, "::") == 0)
662+
strcpy(host_str, "::1");
652663

653664
/*
654665
* We need to set connect_timeout otherwise on Windows

0 commit comments

Comments
 (0)