pgsql: Fix copy-paste error in datum_to_jsonb_internal()

From: Amit Langote <amitlan(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix copy-paste error in datum_to_jsonb_internal()
Date: 2025-03-13 00:59:08
Message-ID: E1tsWui-002BIA-32@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix copy-paste error in datum_to_jsonb_internal()

Commit 3c152a27b06 mistakenly repeated JSONTYPE_JSON in a condition,
omitting JSONTYPE_CAST. As a result, datum_to_jsonb_internal() failed
to reject inputs that were casts (e.g., from an enum to json as in the
example below) when used as keys in JSON constructors.

This led to a crash in cases like:

SELECT JSON_OBJECT('happy'::mood: '123'::jsonb);

where 'happy'::mood is implicitly cast to json. The missing check
meant such casted values weren’t properly rejected as invalid
(non-scalar) JSON keys.

Reported-by: Maciek Sakrejda <maciek(at)pganalyze(dot)com>
Reviewed-by: Tender Wang <tndrwang(at)gmail(dot)com>
Reviewed-by: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Reviewed-by: Maciek Sakrejda <maciek(at)pganalyze(dot)com>
Discussion: https://postgr.es/m/CADXhmgTJtJZK9A3Na_ry+Xrq-ghjcejBRhcRMzWZvbd__QdgJA@mail.gmail.com
Backpatch-through: 17

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d4f79865d4207bd93fa00f521638c289f036e276

Modified Files
--------------
src/backend/utils/adt/jsonb.c | 2 +-
src/test/regress/expected/sqljson.out | 12 ++++++++++++
src/test/regress/sql/sqljson.sql | 11 +++++++++++
3 files changed, 24 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Thomas Munro 2025-03-13 03:00:23 pgsql: Fix read_stream.c for changing io_combine_limit.
Previous Message Amit Langote 2025-03-13 00:58:54 pgsql: Fix copy-paste error in datum_to_jsonb_internal()