postgres.git / summary / log / commit / refs
commit d7de7fa84d2492f15747163cbb2f4c5c110ec4a4
Author: Nathan Bossart <nathan@postgresql.org>
Commit: Noah Misch <noah@leadboat.com>
Date: Mon May 11 12:13:49 2026 +0000
First released in: 19.0, 17.10, 18.4
pg_createsubscriber: Obstruct SQL injection via subscription names.
drop_existing_subscription() neglected to escape the subscription
name when generating its query string. To fix, use
PQescapeIdentifier() to construct a properly escaped name, and use
it in the ALTER SUBSCRIPTION and DROP SUBSCRIPTION commands.
Reported-by: Yu Kunpeng <yu443940816@live.com>
Author: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Security: CVE-2026-6476
Backpatch-through: 17
src/bin/pg_basebackup/pg_createsubscriber.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c
index bad464136e2..eb90c23ca0d 100644
--- a/src/bin/pg_basebackup/pg_createsubscriber.c
+++ b/src/bin/pg_basebackup/pg_createsubscriber.c
@@ -1063,18 +1063,23 @@ drop_existing_subscriptions(PGconn *conn, const char *subname, const char *dbnam
{
PQExpBuffer query = createPQExpBuffer();
PGresult *res;
+ char *subname_esc;
Assert(conn != NULL);
+ subname_esc = PQescapeIdentifier(conn, subname, strlen(subname));
+
/*
* Construct a query string. These commands are allowed to be executed
* within a transaction.
*/
appendPQExpBuffer(query, "ALTER SUBSCRIPTION %s DISABLE;",
- subname);
+ subname_esc);
appendPQExpBuffer(query, " ALTER SUBSCRIPTION %s SET (slot_name = NONE);",
- subname);
- appendPQExpBuffer(query, " DROP SUBSCRIPTION %s;", subname);
+ subname_esc);
+ appendPQExpBuffer(query, " DROP SUBSCRIPTION %s;", subname_esc);
+
+ PQfreemem(subname_esc);
pg_log_info("dropping subscription \"%s\" in database \"%s\"",
subname, dbname);
[parent: a386d14feb21]