postgres.git / summary / log / commit / refs

commit    2b656cbd2f24edb7e2964fa3f71ca253ee9d81d8
Author:   Alvaro Herrera <alvherre@alvh.no-ip.org>
Date:     Tue Jan 16 11:27:52 2024 +0000
First released in: 17.0, 14.11, 15.6, 16.2

    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.


src/interfaces/libpq/fe-exec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 826bf6cebbd..c9450ecff18 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -846,6 +846,8 @@ pqSaveWriteError(PGconn *conn) * using whatever is in conn->errorMessage. In any case, clear the async * result storage, and update our notion of how much error text has been * returned to the application. + * + * Note that in no case (not even OOM) do we return NULL. */ PGresult * pqPrepareAsyncResult(PGconn *conn) @@ -2153,7 +2155,7 @@ PQgetResult(PGconn *conn) * (In other words: we don't return a NULL after a pipeline * sync.) */ - if (res && res->resultStatus == PGRES_PIPELINE_SYNC) + if (res->resultStatus == PGRES_PIPELINE_SYNC) pqPipelineProcessQueue(conn); } else [parent: 1a4e54617398]