pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json 4+ messages / 1 participants [nested] [flat]
* pgsql: SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json @ 2026-11-05 07:31 Amit Langote <amitlan@postgresql.org> 0 siblings, 0 replies; 4+ messages in thread From: Amit Langote @ 2026-11-05 07:31 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json/jsonb Once JSON_VALUE(... RETURNING json/jsonb) returned NULL, every later evaluation of the same expression in the same statement also returned NULL, even for inputs that had a valid value. In ExecEvalJsonExprPath(), the JSON_VALUE_OP branch for RETURNING json or jsonb converts the matched item to its string form but, unlike the sibling branches, never sets *op->resnull to false. So a NULL result from a previous evaluation, whether due to a JSON null item, an empty match, or an error handled by NULL ON ERROR, remained in effect. That caused the subsequent coercion via the type's input function, which is guarded by that flag, to be skipped, and the valid item to be returned as SQL NULL. The result thus depended on what earlier rows, or earlier expressions sharing the same ExprState, had returned. Fix by setting *op->resnull to false in that branch. Also add a comment noting that ExecGetJsonValueItemString() takes care of that in the final branch. Oversight in commit 6185c9737cf, so back-patch to 17. Bug: #19695 Reported-by: Chaitanya Choudhary <chaitanyyachoudhary@gmail.com> Author: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Reviewed-by: Manu <manuelreyesbravo@gmail.com> Discussion: https://postgr.es/m/19695-2f2c573ef1660737@postgresql.org Backpatch-through: 17 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/31af62f380c658301061f484e94151f1ef71b013 Modified Files -------------- src/backend/executor/execExprInterp.c | 2 + src/test/regress/expected/sqljson_queryfuncs.out | 49 ++++++++++++++++++++++++ src/test/regress/sql/sqljson_queryfuncs.sql | 10 +++++ 3 files changed, 61 insertions(+) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json @ 2026-11-05 07:31 Amit Langote <amitlan@postgresql.org> 0 siblings, 0 replies; 4+ messages in thread From: Amit Langote @ 2026-11-05 07:31 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json/jsonb Once JSON_VALUE(... RETURNING json/jsonb) returned NULL, every later evaluation of the same expression in the same statement also returned NULL, even for inputs that had a valid value. In ExecEvalJsonExprPath(), the JSON_VALUE_OP branch for RETURNING json or jsonb converts the matched item to its string form but, unlike the sibling branches, never sets *op->resnull to false. So a NULL result from a previous evaluation, whether due to a JSON null item, an empty match, or an error handled by NULL ON ERROR, remained in effect. That caused the subsequent coercion via the type's input function, which is guarded by that flag, to be skipped, and the valid item to be returned as SQL NULL. The result thus depended on what earlier rows, or earlier expressions sharing the same ExprState, had returned. Fix by setting *op->resnull to false in that branch. Also add a comment noting that ExecGetJsonValueItemString() takes care of that in the final branch. Oversight in commit 6185c9737cf, so back-patch to 17. Bug: #19695 Reported-by: Chaitanya Choudhary <chaitanyyachoudhary@gmail.com> Author: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Reviewed-by: Manu <manuelreyesbravo@gmail.com> Discussion: https://postgr.es/m/19695-2f2c573ef1660737@postgresql.org Backpatch-through: 17 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/7150d0fd494166107e6efcc7e786690fd76eff08 Modified Files -------------- src/backend/executor/execExprInterp.c | 2 + src/test/regress/expected/sqljson_queryfuncs.out | 49 ++++++++++++++++++++++++ src/test/regress/sql/sqljson_queryfuncs.sql | 10 +++++ 3 files changed, 61 insertions(+) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json @ 2026-11-05 07:31 Amit Langote <amitlan@postgresql.org> 0 siblings, 0 replies; 4+ messages in thread From: Amit Langote @ 2026-11-05 07:31 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json/jsonb Once JSON_VALUE(... RETURNING json/jsonb) returned NULL, every later evaluation of the same expression in the same statement also returned NULL, even for inputs that had a valid value. In ExecEvalJsonExprPath(), the JSON_VALUE_OP branch for RETURNING json or jsonb converts the matched item to its string form but, unlike the sibling branches, never sets *op->resnull to false. So a NULL result from a previous evaluation, whether due to a JSON null item, an empty match, or an error handled by NULL ON ERROR, remained in effect. That caused the subsequent coercion via the type's input function, which is guarded by that flag, to be skipped, and the valid item to be returned as SQL NULL. The result thus depended on what earlier rows, or earlier expressions sharing the same ExprState, had returned. Fix by setting *op->resnull to false in that branch. Also add a comment noting that ExecGetJsonValueItemString() takes care of that in the final branch. Oversight in commit 6185c9737cf, so back-patch to 17. Bug: #19695 Reported-by: Chaitanya Choudhary <chaitanyyachoudhary@gmail.com> Author: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Reviewed-by: Manu <manuelreyesbravo@gmail.com> Discussion: https://postgr.es/m/19695-2f2c573ef1660737@postgresql.org Backpatch-through: 17 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/2f2c923c33504c32bc70d359756c451769110c05 Modified Files -------------- src/backend/executor/execExprInterp.c | 2 + src/test/regress/expected/sqljson_queryfuncs.out | 49 ++++++++++++++++++++++++ src/test/regress/sql/sqljson_queryfuncs.sql | 10 +++++ 3 files changed, 61 insertions(+) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json @ 2026-11-05 07:32 Amit Langote <amitlan@postgresql.org> 0 siblings, 0 replies; 4+ messages in thread From: Amit Langote @ 2026-11-05 07:32 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json/jsonb Once JSON_VALUE(... RETURNING json/jsonb) returned NULL, every later evaluation of the same expression in the same statement also returned NULL, even for inputs that had a valid value. In ExecEvalJsonExprPath(), the JSON_VALUE_OP branch for RETURNING json or jsonb converts the matched item to its string form but, unlike the sibling branches, never sets *op->resnull to false. So a NULL result from a previous evaluation, whether due to a JSON null item, an empty match, or an error handled by NULL ON ERROR, remained in effect. That caused the subsequent coercion via the type's input function, which is guarded by that flag, to be skipped, and the valid item to be returned as SQL NULL. The result thus depended on what earlier rows, or earlier expressions sharing the same ExprState, had returned. Fix by setting *op->resnull to false in that branch. Also add a comment noting that ExecGetJsonValueItemString() takes care of that in the final branch. Oversight in commit 6185c9737cf, so back-patch to 17. Bug: #19695 Reported-by: Chaitanya Choudhary <chaitanyyachoudhary@gmail.com> Author: Srinath Reddy Sadipiralla <srinath2133@gmail.com> Reviewed-by: Manu <manuelreyesbravo@gmail.com> Discussion: https://postgr.es/m/19695-2f2c573ef1660737@postgresql.org Backpatch-through: 17 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/627c4df3b73ae00a0dfd08f4216514fb9ea44b5d Modified Files -------------- src/backend/executor/execExprInterp.c | 2 + src/test/regress/expected/sqljson_queryfuncs.out | 49 ++++++++++++++++++++++++ src/test/regress/sql/sqljson_queryfuncs.sql | 10 +++++ 3 files changed, 61 insertions(+) ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2026-11-05 07:32 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-11-05 07:31 pgsql: SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json Amit Langote <amitlan@postgresql.org> 2026-11-05 07:31 pgsql: SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json Amit Langote <amitlan@postgresql.org> 2026-11-05 07:31 pgsql: SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json Amit Langote <amitlan@postgresql.org> 2026-11-05 07:32 pgsql: SQL/JSON: Fix NULL result leakage in JSON_VALUE() RETURNING json Amit Langote <amitlan@postgresql.org>
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