agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: refint: Fix segfault in check_foreign_key().
6+ messages / 1 participants
[nested] [flat]

* pgsql: refint: Fix segfault in check_foreign_key().
@ 2026-05-14 18:13 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Nathan Bossart @ 2026-05-14 18:13 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

refint: Fix segfault in check_foreign_key().

When an UPDATE statement triggers check_foreign_key() with the
action set to "cascade", it generates more UPDATE statements to
modify the key values in referencing relations.  If a new key value
is NULL, SPI_getvalue() returns a NULL pointer, which is
subsequently passed to quote_literal_cstr(), causing a segfault.
To fix, skip quoting when a new key value is NULL and insert an
unquoted NULL keyword instead.

Oversight in commit 260e97733b.  While the refint documentation
recommends marking primary key columns NOT NULL, the aforementioned
scenario accidentally worked on platforms where snprintf()
substitutes "(null)" for NULL pointers.  Note that for
character-type columns, the old code quoted "(null)" as a string
literal, so this didn't always produce correct results.  But it
still seems better to fix this than to reject cases that previously
worked.

Reported-by: Nikita Kalinin <n.kalinin@postgrespro.ru>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com>
Discussion: https://postgr.es/m/19476-bd04ea6241345303%40postgresql.org
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/611756948eef3a3a1babc3418fc254077528b679

Modified Files
--------------
contrib/spi/refint.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: refint: Fix segfault in check_foreign_key().
@ 2026-05-14 18:13 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Nathan Bossart @ 2026-05-14 18:13 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

refint: Fix segfault in check_foreign_key().

When an UPDATE statement triggers check_foreign_key() with the
action set to "cascade", it generates more UPDATE statements to
modify the key values in referencing relations.  If a new key value
is NULL, SPI_getvalue() returns a NULL pointer, which is
subsequently passed to quote_literal_cstr(), causing a segfault.
To fix, skip quoting when a new key value is NULL and insert an
unquoted NULL keyword instead.

Oversight in commit 260e97733b.  While the refint documentation
recommends marking primary key columns NOT NULL, the aforementioned
scenario accidentally worked on platforms where snprintf()
substitutes "(null)" for NULL pointers.  Note that for
character-type columns, the old code quoted "(null)" as a string
literal, so this didn't always produce correct results.  But it
still seems better to fix this than to reject cases that previously
worked.

Reported-by: Nikita Kalinin <n.kalinin@postgrespro.ru>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com>
Discussion: https://postgr.es/m/19476-bd04ea6241345303%40postgresql.org
Backpatch-through: 14

Branch
------
REL_18_STABLE

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

Modified Files
--------------
contrib/spi/refint.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: refint: Fix segfault in check_foreign_key().
@ 2026-05-14 18:13 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Nathan Bossart @ 2026-05-14 18:13 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

refint: Fix segfault in check_foreign_key().

When an UPDATE statement triggers check_foreign_key() with the
action set to "cascade", it generates more UPDATE statements to
modify the key values in referencing relations.  If a new key value
is NULL, SPI_getvalue() returns a NULL pointer, which is
subsequently passed to quote_literal_cstr(), causing a segfault.
To fix, skip quoting when a new key value is NULL and insert an
unquoted NULL keyword instead.

Oversight in commit 260e97733b.  While the refint documentation
recommends marking primary key columns NOT NULL, the aforementioned
scenario accidentally worked on platforms where snprintf()
substitutes "(null)" for NULL pointers.  Note that for
character-type columns, the old code quoted "(null)" as a string
literal, so this didn't always produce correct results.  But it
still seems better to fix this than to reject cases that previously
worked.

Reported-by: Nikita Kalinin <n.kalinin@postgrespro.ru>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com>
Discussion: https://postgr.es/m/19476-bd04ea6241345303%40postgresql.org
Backpatch-through: 14

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6b4de201e82f938b159033bb9d664e91107bf051

Modified Files
--------------
contrib/spi/refint.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: refint: Fix segfault in check_foreign_key().
@ 2026-05-14 18:13 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Nathan Bossart @ 2026-05-14 18:13 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

refint: Fix segfault in check_foreign_key().

When an UPDATE statement triggers check_foreign_key() with the
action set to "cascade", it generates more UPDATE statements to
modify the key values in referencing relations.  If a new key value
is NULL, SPI_getvalue() returns a NULL pointer, which is
subsequently passed to quote_literal_cstr(), causing a segfault.
To fix, skip quoting when a new key value is NULL and insert an
unquoted NULL keyword instead.

Oversight in commit 260e97733b.  While the refint documentation
recommends marking primary key columns NOT NULL, the aforementioned
scenario accidentally worked on platforms where snprintf()
substitutes "(null)" for NULL pointers.  Note that for
character-type columns, the old code quoted "(null)" as a string
literal, so this didn't always produce correct results.  But it
still seems better to fix this than to reject cases that previously
worked.

Reported-by: Nikita Kalinin <n.kalinin@postgrespro.ru>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com>
Discussion: https://postgr.es/m/19476-bd04ea6241345303%40postgresql.org
Backpatch-through: 14

Branch
------
REL_16_STABLE

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

Modified Files
--------------
contrib/spi/refint.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: refint: Fix segfault in check_foreign_key().
@ 2026-05-14 18:13 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Nathan Bossart @ 2026-05-14 18:13 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

refint: Fix segfault in check_foreign_key().

When an UPDATE statement triggers check_foreign_key() with the
action set to "cascade", it generates more UPDATE statements to
modify the key values in referencing relations.  If a new key value
is NULL, SPI_getvalue() returns a NULL pointer, which is
subsequently passed to quote_literal_cstr(), causing a segfault.
To fix, skip quoting when a new key value is NULL and insert an
unquoted NULL keyword instead.

Oversight in commit 260e97733b.  While the refint documentation
recommends marking primary key columns NOT NULL, the aforementioned
scenario accidentally worked on platforms where snprintf()
substitutes "(null)" for NULL pointers.  Note that for
character-type columns, the old code quoted "(null)" as a string
literal, so this didn't always produce correct results.  But it
still seems better to fix this than to reject cases that previously
worked.

Reported-by: Nikita Kalinin <n.kalinin@postgrespro.ru>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com>
Discussion: https://postgr.es/m/19476-bd04ea6241345303%40postgresql.org
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/77b2d18e9c3b1d42576cfb8c46c25592eb908780

Modified Files
--------------
contrib/spi/refint.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: refint: Fix segfault in check_foreign_key().
@ 2026-05-14 18:13 Nathan Bossart <nathan@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: Nathan Bossart @ 2026-05-14 18:13 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

refint: Fix segfault in check_foreign_key().

When an UPDATE statement triggers check_foreign_key() with the
action set to "cascade", it generates more UPDATE statements to
modify the key values in referencing relations.  If a new key value
is NULL, SPI_getvalue() returns a NULL pointer, which is
subsequently passed to quote_literal_cstr(), causing a segfault.
To fix, skip quoting when a new key value is NULL and insert an
unquoted NULL keyword instead.

Oversight in commit 260e97733b.  While the refint documentation
recommends marking primary key columns NOT NULL, the aforementioned
scenario accidentally worked on platforms where snprintf()
substitutes "(null)" for NULL pointers.  Note that for
character-type columns, the old code quoted "(null)" as a string
literal, so this didn't always produce correct results.  But it
still seems better to fix this than to reject cases that previously
worked.

Reported-by: Nikita Kalinin <n.kalinin@postgrespro.ru>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Pierre Forstmann <pierre.forstmann@gmail.com>
Discussion: https://postgr.es/m/19476-bd04ea6241345303%40postgresql.org
Backpatch-through: 14

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1de0a711db9b0656733789df44c7bc4e4ddfc9fd

Modified Files
--------------
contrib/spi/refint.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2026-05-14 18:13 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-05-14 18:13 pgsql: refint: Fix segfault in check_foreign_key(). Nathan Bossart <nathan@postgresql.org>
2026-05-14 18:13 pgsql: refint: Fix segfault in check_foreign_key(). Nathan Bossart <nathan@postgresql.org>
2026-05-14 18:13 pgsql: refint: Fix segfault in check_foreign_key(). Nathan Bossart <nathan@postgresql.org>
2026-05-14 18:13 pgsql: refint: Fix segfault in check_foreign_key(). Nathan Bossart <nathan@postgresql.org>
2026-05-14 18:13 pgsql: refint: Fix segfault in check_foreign_key(). Nathan Bossart <nathan@postgresql.org>
2026-05-14 18:13 pgsql: refint: Fix segfault in check_foreign_key(). Nathan Bossart <nathan@postgresql.org>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox