Magnus Hagander wrote:
> I get a crash on win32 when connecting to a server that's not started.
> In fe-connect.c, we have:
>
> display_host_addr = (conn->pghostaddr == NULL) &&
> (strcmp(conn->pghost, host_addr) != 0);
>
> In my case, conn->pghost is NULL at this point, as is
> conn->pghostaddr. Thus, it crashes in strcmp().
I have researched this with Magnus, and was able to reproduce the
failure. It happens only on Win32 because that is missing unix-domain
sockets so "" maps to localhost, which is an IP address. I have applied
the attached patch. The new output is:
$ psql test
psql: could not connect to server: Connection refused
Is the server running on host "???" and accepting
TCP/IP connections on port 5432?
Note the "???". This happens because the mapping of "" to localhost
happens below the libpq library variable level.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index b1523a6..8d9400b 100644
*** /tmp/pgrevert.7311/PXMjec_fe-connect.c Thu Dec 16 08:36:11 2010
--- src/interfaces/libpq/fe-connect.c Thu Dec 16 08:31:51 2010
*************** connectFailureMessage(PGconn *conn, int
*** 1031,1037 ****
strcpy(host_addr, "???");
display_host_addr = (conn->pghostaddr == NULL) &&
! (strcmp(conn->pghost, host_addr) != 0);
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not connect to server: %s\n"
--- 1031,1038 ----
strcpy(host_addr, "???");
display_host_addr = (conn->pghostaddr == NULL) &&
! (conn->pghost != NULL) &&
! (strcmp(conn->pghost, host_addr) != 0);
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not connect to server: %s\n"