Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7f42350

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 b17ff07 commit 7f42350

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
@@ -540,9 +540,9 @@ bool
540540
IsLockTableGeneric(Archive *AHX)
541541
{
542542
ArchiveHandle *AH = (ArchiveHandle *) AHX;
543-
PGresult *res;
544-
char *sqlstate;
545-
bool retval;
543+
PGresult *res;
544+
char *sqlstate;
545+
bool retval;
546546

547547
if (AHX->remoteVersion >= 140000)
548548
return true;
@@ -569,13 +569,15 @@ IsLockTableGeneric(Archive *AHX)
569569
break;
570570
case PGRES_FATAL_ERROR:
571571
sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
572-
if (strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
572+
if (sqlstate &&
573+
strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
573574
{
574575
retval = false;
575576
break;
576577
}
577-
else if (strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
578-
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0)
578+
else if (sqlstate &&
579+
(strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
580+
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0))
579581
{
580582
retval = true;
581583
break;

0 commit comments

Comments
 (0)