Fix SendRemoteCommandParams() handling of a NULL MultiConnection->pgConn. (#1271)

Previously we'd segfault in PQisnonblocking() which, contrary to other
libpq calls, doesn't handle a NULL PQconn (because there'd be no
appropriate return value for that).

cr: @jasonmp85
pull/1387/head
Andres Freund 2017-03-03 11:02:15 -08:00
parent 2d6915c82a
commit 09c42481bb
1 changed files with 17 additions and 2 deletions

View File

@ -277,11 +277,22 @@ SendRemoteCommandParams(MultiConnection *connection, const char *command,
const char *const *parameterValues) const char *const *parameterValues)
{ {
PGconn *pgConn = connection->pgConn; PGconn *pgConn = connection->pgConn;
bool wasNonblocking = PQisnonblocking(pgConn); bool wasNonblocking = false;
int rc = 0; int rc = 0;
LogRemoteCommand(connection, command); LogRemoteCommand(connection, command);
/*
* Don't try to send command if connection is entirely gone
* (PQisnonblocking() would crash).
*/
if (!pgConn)
{
return 0;
}
wasNonblocking = PQisnonblocking(pgConn);
/* make sure not to block anywhere */ /* make sure not to block anywhere */
if (!wasNonblocking) if (!wasNonblocking)
{ {
@ -340,7 +351,11 @@ GetRemoteCommandResult(MultiConnection *connection, bool raiseInterrupts)
PGresult *result = NULL; PGresult *result = NULL;
bool failed = false; bool failed = false;
/* short circuit tests around the more expensive parts of this routine */ /*
* Short circuit tests around the more expensive parts of this
* routine. This'd also trigger a return in the, unlikely, case of a
* failed/nonexistant connection.
*/
if (!PQisBusy(pgConn)) if (!PQisBusy(pgConn))
{ {
return PQgetResult(connection->pgConn); return PQgetResult(connection->pgConn);