Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Handle PQresultErrorField(PG_DIAG_SQLSTATE) returning NULL in streamutil.c.
authorAndres Freund <andres@anarazel.de>
Wed, 12 Aug 2015 15:35:50 +0000 (17:35 +0200)
committerAndres Freund <andres@anarazel.de>
Wed, 12 Aug 2015 15:35:50 +0000 (17:35 +0200)
In ff27db5d I missed that PQresultErrorField() may return NULL if
there's no sqlstate associated with an error.

Spotted-By: Coverity
Reported-By: Michael Paquier
Discussion: CAB7nPqQ3o10SY6NVdU4pjq85GQTN5tbbkq2gnNUh2fBNU3rKyQ@mail.gmail.com
Backpatch: 9.5, like ff27db5d

src/bin/pg_basebackup/streamutil.c

index 91f919c34cd6f248cbaadb74eabdb8a413941b2c..2c963b67a327adea6de25695674ce11e6a42ea62 100644 (file)
@@ -340,7 +340,9 @@ CreateReplicationSlot(PGconn *conn, const char *slot_name, const char *plugin,
    {
        const char *sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE);
 
-       if (slot_exists_ok && strcmp(sqlstate, ERRCODE_DUPLICATE_OBJECT) == 0)
+       if (slot_exists_ok &&
+           sqlstate &&
+           strcmp(sqlstate, ERRCODE_DUPLICATE_OBJECT) == 0)
        {
            destroyPQExpBuffer(query);
            PQclear(res);