Incorrect matching of sql/json PASSING variable names

Started by Amit Langotealmost 2 years ago3 messageshackers
Jump to latest
#1Amit Langote
Langote_Amit_f8@lab.ntt.co.jp

Hi,

Alvaro reported off-list that the following should really fail,
because the jsonpath expression refers to a PASSING variable that
doesn't exist:

select json_query('"1"', jsonpath '$xy' passing 2 AS xyz);
json_query
------------
2
(1 row)

This works because of a bug in GetJsonPathVar() whereby it allows a
jsonpath expression to reference any prefix of the PASSING variable
names.

Attached is a patch to fix that.

Thanks Alvaro for the report.

--
Thanks, Amit Langote

Attachments:

v1-0001-in-transformJsonBehavior-better-handle-default-ex.patchapplication/octet-stream; name=v1-0001-in-transformJsonBehavior-better-handle-default-ex.patchDownload+71-5
#2Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Amit Langote (#1)
Re: Incorrect matching of sql/json PASSING variable names

On Thu, Jun 6, 2024 at 6:20 PM Amit Langote <amitlangote09@gmail.com> wrote:

Hi,

Alvaro reported off-list that the following should really fail,
because the jsonpath expression refers to a PASSING variable that
doesn't exist:

select json_query('"1"', jsonpath '$xy' passing 2 AS xyz);
json_query
------------
2
(1 row)

This works because of a bug in GetJsonPathVar() whereby it allows a
jsonpath expression to reference any prefix of the PASSING variable
names.

Attached is a patch to fix that.

Here's an updated version that I'll push tomorrow.

--
Thanks, Amit Langote

Attachments:

v2-0001-SQL-JSON-Correct-jsonpath-variable-name-matching.patchapplication/octet-stream; name=v2-0001-SQL-JSON-Correct-jsonpath-variable-name-matching.patchDownload+21-2
#3Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Amit Langote (#2)
Re: Incorrect matching of sql/json PASSING variable names

On Thu, Jun 13, 2024 at 5:04 PM Amit Langote <amitlangote09@gmail.com> wrote:

On Thu, Jun 6, 2024 at 6:20 PM Amit Langote <amitlangote09@gmail.com> wrote:

Hi,

Alvaro reported off-list that the following should really fail,
because the jsonpath expression refers to a PASSING variable that
doesn't exist:

select json_query('"1"', jsonpath '$xy' passing 2 AS xyz);
json_query
------------
2
(1 row)

This works because of a bug in GetJsonPathVar() whereby it allows a
jsonpath expression to reference any prefix of the PASSING variable
names.

Attached is a patch to fix that.

Here's an updated version that I'll push tomorrow.

Pushed.

(Seems like pgsql-committers notification has stalled.)

--
Thanks, Amit Langote