Commit 7f423503 authored by Tom Lane's avatar Tom Lane

Avoid null pointer dereference if error result lacks SQLSTATE.

Although error results received from the backend should always have
a SQLSTATE field, ones generated by libpq won't, making this code
vulnerable to a crash after, say, untimely loss of connection.
Noted by Coverity.

Oversight in commit 403a3d91.  Back-patch to 9.5, as that was.
parent b17ff07a
......@@ -540,9 +540,9 @@ bool
IsLockTableGeneric(Archive *AHX)
{
ArchiveHandle *AH = (ArchiveHandle *) AHX;
PGresult *res;
char *sqlstate;
bool retval;
PGresult *res;
char *sqlstate;
bool retval;
if (AHX->remoteVersion >= 140000)
return true;
......@@ -569,13 +569,15 @@ IsLockTableGeneric(Archive *AHX)
break;
case PGRES_FATAL_ERROR:
sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
if (strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
if (sqlstate &&
strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
{
retval = false;
break;
}
else if (strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0)
else if (sqlstate &&
(strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0))
{
retval = true;
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment