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

Commit 39aab11

Browse files
committed
Don't test already-referenced pointer for nullness
Commit b8ba734 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 618c167 (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 b8ba734. Per Coverity.
1 parent 23e0ba5 commit 39aab11

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/interfaces/libpq/fe-exec.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,8 @@ pqSaveWriteError(PGconn *conn)
841841
* using whatever is in conn->errorMessage. In any case, clear the async
842842
* result storage, and update our notion of how much error text has been
843843
* returned to the application.
844+
*
845+
* Note that in no case (not even OOM) do we return NULL.
844846
*/
845847
PGresult *
846848
pqPrepareAsyncResult(PGconn *conn)
@@ -2137,7 +2139,7 @@ PQgetResult(PGconn *conn)
21372139
* (In other words: we don't return a NULL after a pipeline
21382140
* sync.)
21392141
*/
2140-
if (res && res->resultStatus == PGRES_PIPELINE_SYNC)
2142+
if (res->resultStatus == PGRES_PIPELINE_SYNC)
21412143
pqPipelineProcessQueue(conn);
21422144
}
21432145
else

0 commit comments

Comments
 (0)