Skip to content

Commit 7d72fd9

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 41a033b commit 7d72fd9

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
@@ -543,9 +543,9 @@ bool
543543
IsLockTableGeneric(Archive *AHX)
544544
{
545545
ArchiveHandle *AH = (ArchiveHandle *) AHX;
546-
PGresult *res;
547-
char *sqlstate;
548-
bool retval;
546+
PGresult *res;
547+
char *sqlstate;
548+
bool retval;
549549

550550
if (AHX->remoteVersion >= 140000)
551551
return true;
@@ -572,13 +572,15 @@ IsLockTableGeneric(Archive *AHX)
572572
break;
573573
case PGRES_FATAL_ERROR:
574574
sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
575-
if (strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
575+
if (sqlstate &&
576+
strcmp(sqlstate, ERRCODE_WRONG_OBJECT_TYPE) == 0)
576577
{
577578
retval = false;
578579
break;
579580
}
580-
else if (strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
581-
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0)
581+
else if (sqlstate &&
582+
(strcmp(sqlstate, ERRCODE_LOCK_NOT_AVAILABLE) == 0 ||
583+
strcmp(sqlstate, ERRCODE_INSUFFICIENT_PRIVILEGE) == 0))
582584
{
583585
retval = true;
584586
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy