pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix NULLIF()'s handling of read-write expanded objects.
Date: Mon, 25 Nov 2024 23:10:00 +0000
Message-ID: <E1tFiDQ-003WsV-FU@gemulon.postgresql.org> (raw)

Fix NULLIF()'s handling of read-write expanded objects.

If passed a read-write expanded object pointer, the EEOP_NULLIF
code would hand that same pointer to the equality function
and then (unless equality was reported) also return the same
pointer as its value.  This is no good, because a function that
receives a read-write expanded object pointer is fully entitled
to scribble on or even delete the object, thus corrupting the
NULLIF output.  (This problem is likely unobservable with the
equality functions provided in core Postgres, but it's easy to
demonstrate with one coded in plpgsql.)

To fix, make sure the pointer passed to the equality function
is read-only.  We can still return the original read-write
pointer as the NULLIF result, allowing optimization of later
operations.

Per bug #18722 from Alexander Lakhin.  This has been wrong
since we invented expanded objects, so back-patch to all
supported branches.

Discussion: https://postgr.es/m/18722-fd9e645448cc78b4@postgresql.org

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/97be02ad0015502fac0b788bc0a4739a398f41d5

Modified Files
--------------
src/backend/executor/execExpr.c       |  8 ++++++++
src/backend/executor/execExprInterp.c | 14 +++++++++++++-
src/backend/jit/llvm/llvmjit_expr.c   | 33 +++++++++++++++++++++++++++++----
src/include/executor/execExpr.h       |  1 +
src/test/regress/expected/case.out    |  8 ++++++++
src/test/regress/sql/case.sql         |  5 +++++
6 files changed, 64 insertions(+), 5 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1tFiDQ-003WsV-FU@gemulon.postgresql.org>
Permalink:  ../E1tFiDQ-003WsV-FU@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1tFiDQ-003WsV-FU@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix NULLIF()'s handling of read-write expanded objects.
  In-Reply-To: <E1tFiDQ-003WsV-FU@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox