From: Alvaro Herrera Date: Tue, 16 Jan 2024 11:27:52 +0000 (+0100) Subject: Don't test already-referenced pointer for nullness X-Git-Tag: REL_14_11~29 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=7a7c8c98a610418ed0118e22a1793bf27e55783a;p=postgresql.git Don't test already-referenced pointer for nullness Commit b8ba7344e9eb added in PQgetResult a derefence to a pointer returned by pqPrepareAsyncResult(), before some other code that was already testing that pointer for nullness. But since commit 618c16707a6d (in Postgres 15), pqPrepareAsyncResult() doesn't ever return NULL (a statically-allocated result is returned if OOM). So in branches 15 and up, we can remove the redundant pointer check with no harm done. However, in branch 14, pqPrepareAsyncResult() can indeed return NULL if it runs out of memory. Fix things there by adding a null pointer check before dereferencing the pointer. This should hint Coverity that the preexisting check is not redundant but necessary. Backpatch to 14, like b8ba7344e9eb. Per Coverity. --- diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 8895f81add1..a1c946bccd2 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -2091,8 +2091,9 @@ PQgetResult(PGconn *conn) res = pqPrepareAsyncResult(conn); /* Advance the queue as appropriate */ - pqCommandQueueAdvance(conn, false, - res->resultStatus == PGRES_PIPELINE_SYNC); + if (res) + pqCommandQueueAdvance(conn, false, + res->resultStatus == PGRES_PIPELINE_SYNC); if (conn->pipelineStatus != PQ_PIPELINE_OFF) {