pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value 7+ messages / 1 participants [nested] [flat]
* pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value @ 2026-10-19 04:41 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-19 04:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix use-after-free in jsonb_set_lax for Const NULL new_value Commit a83586b5543 decided to scribble on the caller's fcinfo but failed to take into account that const arguments are written once at expression init and assumed never to change. The use_json_null branch overwrote fcinfo->args[2] with a jsonb null built in the per-tuple expression context. In later rows, args[2].isnull is still false and args[2].value still holds that pointer, but the per-tuple context has been reset. Later rows find args[2].isnull = false, short-circuit past the NULL handling at the top of the function, and jump straight to jsonb_set with the stale pointer regardless of their own null_value_treatment argument, which is never read. To fix, call jsonb_set through its own call frame instead. Arguments 0, 1 and 3 were already checked non-NULL above, so we can use DirectFunctionCall4. Add regression tests covering use_json_null followed by delete_key and return_target, and a multi-row default-treatment query. Reported-by: Evan Si <evsi@amazon.com> Discussion: https://postgr.es/m/CANWCAZY-PS=ev8TiiV1j=NoR2xLopEL8fDq0fyQZahHiP5b+Pw@mail.gmail.com Backpatch-through: 14 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/e355089a57d6f480cffc2820c46fcf0b5e371cf6 Modified Files -------------- src/backend/utils/adt/jsonfuncs.c | 8 +++++--- src/test/regress/expected/jsonb.out | 28 ++++++++++++++++++++++++++++ src/test/regress/sql/jsonb.sql | 10 ++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value @ 2026-10-19 04:41 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-19 04:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix use-after-free in jsonb_set_lax for Const NULL new_value Commit a83586b5543 decided to scribble on the caller's fcinfo but failed to take into account that const arguments are written once at expression init and assumed never to change. The use_json_null branch overwrote fcinfo->args[2] with a jsonb null built in the per-tuple expression context. In later rows, args[2].isnull is still false and args[2].value still holds that pointer, but the per-tuple context has been reset. Later rows find args[2].isnull = false, short-circuit past the NULL handling at the top of the function, and jump straight to jsonb_set with the stale pointer regardless of their own null_value_treatment argument, which is never read. To fix, call jsonb_set through its own call frame instead. Arguments 0, 1 and 3 were already checked non-NULL above, so we can use DirectFunctionCall4. Add regression tests covering use_json_null followed by delete_key and return_target, and a multi-row default-treatment query. Reported-by: Evan Si <evsi@amazon.com> Discussion: https://postgr.es/m/CANWCAZY-PS=ev8TiiV1j=NoR2xLopEL8fDq0fyQZahHiP5b+Pw@mail.gmail.com Backpatch-through: 14 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/cb98b23da3a687f842a559bcc0e577b2447f4ba4 Modified Files -------------- src/backend/utils/adt/jsonfuncs.c | 8 +++++--- src/test/regress/expected/jsonb.out | 28 ++++++++++++++++++++++++++++ src/test/regress/sql/jsonb.sql | 10 ++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value @ 2026-10-19 04:41 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-19 04:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix use-after-free in jsonb_set_lax for Const NULL new_value Commit a83586b5543 decided to scribble on the caller's fcinfo but failed to take into account that const arguments are written once at expression init and assumed never to change. The use_json_null branch overwrote fcinfo->args[2] with a jsonb null built in the per-tuple expression context. In later rows, args[2].isnull is still false and args[2].value still holds that pointer, but the per-tuple context has been reset. Later rows find args[2].isnull = false, short-circuit past the NULL handling at the top of the function, and jump straight to jsonb_set with the stale pointer regardless of their own null_value_treatment argument, which is never read. To fix, call jsonb_set through its own call frame instead. Arguments 0, 1 and 3 were already checked non-NULL above, so we can use DirectFunctionCall4. Add regression tests covering use_json_null followed by delete_key and return_target, and a multi-row default-treatment query. Reported-by: Evan Si <evsi@amazon.com> Discussion: https://postgr.es/m/CANWCAZY-PS=ev8TiiV1j=NoR2xLopEL8fDq0fyQZahHiP5b+Pw@mail.gmail.com Backpatch-through: 14 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/52af12e9d908fd528bc347a0c01bb931d3c89010 Modified Files -------------- src/backend/utils/adt/jsonfuncs.c | 8 +++++--- src/test/regress/expected/jsonb.out | 28 ++++++++++++++++++++++++++++ src/test/regress/sql/jsonb.sql | 10 ++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value @ 2026-10-19 04:41 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-19 04:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix use-after-free in jsonb_set_lax for Const NULL new_value Commit a83586b5543 decided to scribble on the caller's fcinfo but failed to take into account that const arguments are written once at expression init and assumed never to change. The use_json_null branch overwrote fcinfo->args[2] with a jsonb null built in the per-tuple expression context. In later rows, args[2].isnull is still false and args[2].value still holds that pointer, but the per-tuple context has been reset. Later rows find args[2].isnull = false, short-circuit past the NULL handling at the top of the function, and jump straight to jsonb_set with the stale pointer regardless of their own null_value_treatment argument, which is never read. To fix, call jsonb_set through its own call frame instead. Arguments 0, 1 and 3 were already checked non-NULL above, so we can use DirectFunctionCall4. Add regression tests covering use_json_null followed by delete_key and return_target, and a multi-row default-treatment query. Reported-by: Evan Si <evsi@amazon.com> Discussion: https://postgr.es/m/CANWCAZY-PS=ev8TiiV1j=NoR2xLopEL8fDq0fyQZahHiP5b+Pw@mail.gmail.com Backpatch-through: 14 Branch ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/723075b0315d7a71c8d99252938f3582c6c1cee9 Modified Files -------------- src/backend/utils/adt/jsonfuncs.c | 8 +++++--- src/test/regress/expected/jsonb.out | 28 ++++++++++++++++++++++++++++ src/test/regress/sql/jsonb.sql | 10 ++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value @ 2026-10-19 04:41 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-19 04:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix use-after-free in jsonb_set_lax for Const NULL new_value Commit a83586b5543 decided to scribble on the caller's fcinfo but failed to take into account that const arguments are written once at expression init and assumed never to change. The use_json_null branch overwrote fcinfo->args[2] with a jsonb null built in the per-tuple expression context. In later rows, args[2].isnull is still false and args[2].value still holds that pointer, but the per-tuple context has been reset. Later rows find args[2].isnull = false, short-circuit past the NULL handling at the top of the function, and jump straight to jsonb_set with the stale pointer regardless of their own null_value_treatment argument, which is never read. To fix, call jsonb_set through its own call frame instead. Arguments 0, 1 and 3 were already checked non-NULL above, so we can use DirectFunctionCall4. Add regression tests covering use_json_null followed by delete_key and return_target, and a multi-row default-treatment query. Reported-by: Evan Si <evsi@amazon.com> Discussion: https://postgr.es/m/CANWCAZY-PS=ev8TiiV1j=NoR2xLopEL8fDq0fyQZahHiP5b+Pw@mail.gmail.com Backpatch-through: 14 Branch ------ REL_16_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/4a3177299f678043e36f6fad075ce3d69301b4a5 Modified Files -------------- src/backend/utils/adt/jsonfuncs.c | 8 +++++--- src/test/regress/expected/jsonb.out | 28 ++++++++++++++++++++++++++++ src/test/regress/sql/jsonb.sql | 10 ++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value @ 2026-10-19 04:41 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-19 04:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix use-after-free in jsonb_set_lax for Const NULL new_value Commit a83586b5543 decided to scribble on the caller's fcinfo but failed to take into account that const arguments are written once at expression init and assumed never to change. The use_json_null branch overwrote fcinfo->args[2] with a jsonb null built in the per-tuple expression context. In later rows, args[2].isnull is still false and args[2].value still holds that pointer, but the per-tuple context has been reset. Later rows find args[2].isnull = false, short-circuit past the NULL handling at the top of the function, and jump straight to jsonb_set with the stale pointer regardless of their own null_value_treatment argument, which is never read. To fix, call jsonb_set through its own call frame instead. Arguments 0, 1 and 3 were already checked non-NULL above, so we can use DirectFunctionCall4. Add regression tests covering use_json_null followed by delete_key and return_target, and a multi-row default-treatment query. Reported-by: Evan Si <evsi@amazon.com> Discussion: https://postgr.es/m/CANWCAZY-PS=ev8TiiV1j=NoR2xLopEL8fDq0fyQZahHiP5b+Pw@mail.gmail.com Backpatch-through: 14 Branch ------ REL_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/b3477b1cab4365b3aa6f97c33bf18bfecec3b159 Modified Files -------------- src/backend/utils/adt/jsonfuncs.c | 8 +++++--- src/test/regress/expected/jsonb.out | 28 ++++++++++++++++++++++++++++ src/test/regress/sql/jsonb.sql | 10 ++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
* pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value @ 2026-10-19 04:41 John Naylor <john.naylor@postgresql.org> 0 siblings, 0 replies; 7+ messages in thread From: John Naylor @ 2026-10-19 04:41 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix use-after-free in jsonb_set_lax for Const NULL new_value Commit a83586b5543 decided to scribble on the caller's fcinfo but failed to take into account that const arguments are written once at expression init and assumed never to change. The use_json_null branch overwrote fcinfo->args[2] with a jsonb null built in the per-tuple expression context. In later rows, args[2].isnull is still false and args[2].value still holds that pointer, but the per-tuple context has been reset. Later rows find args[2].isnull = false, short-circuit past the NULL handling at the top of the function, and jump straight to jsonb_set with the stale pointer regardless of their own null_value_treatment argument, which is never read. To fix, call jsonb_set through its own call frame instead. Arguments 0, 1 and 3 were already checked non-NULL above, so we can use DirectFunctionCall4. Add regression tests covering use_json_null followed by delete_key and return_target, and a multi-row default-treatment query. Reported-by: Evan Si <evsi@amazon.com> Discussion: https://postgr.es/m/CANWCAZY-PS=ev8TiiV1j=NoR2xLopEL8fDq0fyQZahHiP5b+Pw@mail.gmail.com Backpatch-through: 14 Branch ------ REL_14_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/42b320abe33907fc8449c63ed6c62ad9fba5bd90 Modified Files -------------- src/backend/utils/adt/jsonfuncs.c | 8 +++++--- src/test/regress/expected/jsonb.out | 28 ++++++++++++++++++++++++++++ src/test/regress/sql/jsonb.sql | 10 ++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) ^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2026-10-19 04:41 UTC | newest] Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2026-10-19 04:41 pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value John Naylor <john.naylor@postgresql.org> 2026-10-19 04:41 pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value John Naylor <john.naylor@postgresql.org> 2026-10-19 04:41 pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value John Naylor <john.naylor@postgresql.org> 2026-10-19 04:41 pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value John Naylor <john.naylor@postgresql.org> 2026-10-19 04:41 pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value John Naylor <john.naylor@postgresql.org> 2026-10-19 04:41 pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value John Naylor <john.naylor@postgresql.org> 2026-10-19 04:41 pgsql: Fix use-after-free in jsonb_set_lax for Const NULL new_value John Naylor <john.naylor@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