Skip to content

Commit dd7ae03

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 c39f4e8 commit dd7ae03

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
@@ -546,9 +546,9 @@ bool
546546
IsLockTableGeneric(Archive *AHX)
547547
{
548548
ArchiveHandle *AH = (ArchiveHandle *) AHX;
549-
PGresult *res;
550-
char *sqlstate;
551-
bool retval;
549+
PGresult *res;
550+
char *sqlstate;
551+
bool retval;
552552

553553
if (AHX->remoteVersion >= 140000)
554554
return true;
@@ -575,13 +575,15 @@ IsLockTableGeneric(Archive *AHX)
575575
break;
576576
case PGRES_FATAL_ERROR:
577577
sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
578-
if (strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
578+
if (sqlstate &&
579+
strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
579580
{
580581
retval = false;
581582
break;
582583
}
583-
else if (strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
584-
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0)
584+
else if (sqlstate &&
585+
(strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
586+
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0))
585587
{
586588
retval = true;
587589
break;

0 commit comments

Comments
 (0)