Skip to content

Commit 1127377

Browse files
committed
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 403a3d9. Back-patch to 9.5, as that was.
1 parent 204d779 commit 1127377

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/bin/pg_dump/pg_backup_db.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,9 @@ bool
561561
IsLockTableGeneric(Archive *AHX)
562562
{
563563
ArchiveHandle *AH = (ArchiveHandle *) AHX;
564-
PGresult *res;
565-
char *sqlstate;
566-
bool retval;
564+
PGresult *res;
565+
char *sqlstate;
566+
bool retval;
567567

568568
if (AHX->remoteVersion >= 140000)
569569
return true;
@@ -590,13 +590,15 @@ IsLockTableGeneric(Archive *AHX)
590590
break;
591591
case PGRES_FATAL_ERROR:
592592
sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
593-
if (strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
593+
if (sqlstate &&
594+
strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
594595
{
595596
retval = false;
596597
break;
597598
}
598-
else if (strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
599-
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0)
599+
else if (sqlstate &&
600+
(strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
601+
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0))
600602
{
601603
retval = true;
602604
break;

0 commit comments

Comments
 (0)