Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0041941

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 403a3d91c. Back-patch to 9.5, as that was.
1 parent bb62df4 commit 0041941

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

548548
if (AHX->remoteVersion >= 140000)
549549
return true;
@@ -570,13 +570,15 @@ IsLockTableGeneric(Archive *AHX)
570570
break;
571571
case PGRES_FATAL_ERROR:
572572
sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
573-
if (strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
573+
if (sqlstate &&
574+
strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
574575
{
575576
retval = false;
576577
break;
577578
}
578-
else if (strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
579-
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0)
579+
else if (sqlstate &&
580+
(strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
581+
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0))
580582
{
581583
retval = true;
582584
break;

0 commit comments

Comments
 (0)