agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Amit Langote <amitlan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Report undefined jsonpath variable when no variables are supplie
Date: Thu, 18 Jun 2026 06:56:50 +0000
Message-ID: <E1wa6gE-000pml-2G@gemulon.postgresql.org> (raw)

Report undefined jsonpath variable when no variables are supplied

The two-argument jsonb @? and @@ operators invoke the jsonpath executor
with no variable set.  In that case getJsonPathVariable() treated any
"$name" reference as JSON null and continued evaluating, instead of
reporting the variable as undefined.

This produced incorrect results -- for example '42'::jsonb @? '$"x"'
returned true -- and, for some malformed or hostile jsonpath expressions
with deeply nested predicates, allowed essentially unbounded memory
consumption that could get the backend killed by the OOM killer.

Report the undefined variable as an error in this case as well, reusing
the message already emitted when a variable is not found among supplied
variables.  This matches the behavior of v17 and later, where the
jsonpath executor was reorganized.  Stopping at the first undefined
variable reference also resolves the reported memory-growth case.

Note this is a user-visible change in the back branches: a jsonpath
expression that references a variable while no variables are supplied now
raises an error rather than silently evaluating it as NULL.  The previous
behavior was incorrect, so the change is judged worthwhile.

Bug: #19458
Reported-by: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Author: Andrey Rachitskiy <pl0h0yp1@gmail.com>
Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>
Reviewed-by: Nikita Malakhov <hukutoc@gmail.com>
Reviewed-by: Amit Langote <amitlangote09@gmail.com>
Discussion: https://postgr.es/m/19458-a69c98bc498333ba@postgresql.org
Backpatch-through: 14-16

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/8af173e2837084c462a5ee3478d1dbcd7cc9b1d6

Modified Files
--------------
src/backend/utils/adt/jsonpath_exec.c        | 13 +++++++------
src/test/regress/expected/jsonb_jsonpath.out |  7 +++++++
src/test/regress/sql/jsonb_jsonpath.sql      |  5 +++++
3 files changed, 19 insertions(+), 6 deletions(-)



view thread (3+ messages)  latest in thread

Message-ID: <E1wa6gE-000pml-2G@gemulon.postgresql.org>
Permalink:  ../E1wa6gE-000pml-2G@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wa6gE-000pml-2G@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: amitlan@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Report undefined jsonpath variable when no variables are supplie
  In-Reply-To: <E1wa6gE-000pml-2G@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox