1
0
mirror of https://github.com/postgres/postgres.git synced 2026-01-05 23:38:41 +03:00

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
This commit is contained in:
Tom Lane
2024-11-25 18:08:58 -05:00
parent 4ba84de459
commit 5b8728cd7f
6 changed files with 64 additions and 5 deletions

View File

@@ -242,6 +242,11 @@ SELECT CASE make_ad(1,2)
WHEN array[1,2]::arrdomain THEN 'right'
END;
-- While we're here, also test handling of a NULLIF arg that is a read/write
-- object (bug #18722)
SELECT NULLIF(make_ad(1,2), array[2,3]::arrdomain);
ROLLBACK;
-- Test interaction of CASE with ArrayCoerceExpr (bug #15471)