public inbox for [email protected]
help / color / mirror / Atom feedFrom: Nathan Bossart <[email protected]>
Subject: [PATCH v3 1/1] refint: Fix seg-fault in check_foreign_key().
Date: Thu, 14 May 2026 11:42:40 -0500
While the refint documentation advises marking the primary key
columns NOT NULL, an UPDATE statement that triggered
check_foreign_key(..., 'cascade', ...) and that set a key value to
NULL accidentally worked before commit 260e97733b because sprintf()
inserted "(null)" into the internally-generated SQL statement.
After commit 260e97733b, the new key value is first passed to
quote_literal_cstr(), which seg-faults for a NULL argument. To
fix, skip quoting when a new key value is NULL and insert "NULL"
instead.
Reported-by: Nikita Kalinin <[email protected]>
Author: Ayush Tiwari <[email protected]>
Reviewed-by: Pierre Forstmann <[email protected]>
Discussion: https://postgr.es/m/19476-bd04ea6241345303%40postgresql.org
Backpatch-through: 14
---
contrib/spi/refint.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/contrib/spi/refint.c b/contrib/spi/refint.c
index c44c87bcd96..48512a664d2 100644
--- a/contrib/spi/refint.c
+++ b/contrib/spi/refint.c
@@ -487,7 +487,8 @@ check_foreign_key(PG_FUNCTION_ARGS)
nv = SPI_getvalue(newtuple, tupdesc, fn);
appendStringInfo(&sql, " %s = %s ",
- args2[k], quote_literal_cstr(nv));
+ args2[k],
+ nv ? quote_literal_cstr(nv) : "NULL");
if (k < nkeys)
appendStringInfoString(&sql, ", ");
}
--
2.50.1 (Apple Git-155)
--CN4uTtA78AYCFRt1--
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [PATCH v3 1/1] refint: Fix seg-fault in check_foreign_key().
In-Reply-To: <no-message-id-8880@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox