aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-11-01 11:26:16 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-11-01 11:26:52 -0500
commit29ae4cd82949843d09aa02a8125a5b5087201431 (patch)
tree1c2a2976b49015e5c1e5c2afdf8f877207027444
parentaff06436caf844877f99d32346b076a480e582a7 (diff)
downloadpostgresql-29ae4cd82949843d09aa02a8125a5b5087201431.tar.gz
postgresql-29ae4cd82949843d09aa02a8125a5b5087201431.zip
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 403a3d91c. Back-patch to 9.5, as that was.
-rw-r--r--src/bin/pg_dump/pg_backup_db.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c
index 2fd6789ccea..9f57bdbf8b5 100644
--- a/src/bin/pg_dump/pg_backup_db.c
+++ b/src/bin/pg_dump/pg_backup_db.c
@@ -560,9 +560,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;
@@ -589,13 +589,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;