From ebd9964b99d87975553c28a5813cd741ff96195d Mon Sep 17 00:00:00 2001 From: Jelte Fennema Date: Fri, 6 Jan 2023 15:12:03 +0100 Subject: [PATCH] Quote all identifiers that we use for logical replication (#6604) In #6598 it was noticed that Citus could generate syntactically invalid statements during logical replication. With #6603 we resolved the direct issue, by only generating valid subscription names. But there was also the underlying problem that we did not escape certain identifier strings. While in theory this should be okay since we should only generate names that are valid, this issue reiterated that we should not take this for granted. As an extra line of defense this quotes all identifiers we use during logical replication setup. (cherry picked from commit c2b4087ff0a95bc8a3fe0b079813224a35bfe002) --- .../replication/multi_logical_replication.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/distributed/replication/multi_logical_replication.c b/src/backend/distributed/replication/multi_logical_replication.c index d4e87db0b..59e5c350f 100644 --- a/src/backend/distributed/replication/multi_logical_replication.c +++ b/src/backend/distributed/replication/multi_logical_replication.c @@ -1674,7 +1674,7 @@ CreatePublications(MultiConnection *connection, bool prefixWithComma = false; appendStringInfo(createPublicationCommand, "CREATE PUBLICATION %s FOR TABLE ", - entry->name); + quote_identifier(entry->name)); ShardInterval *shard = NULL; foreach_ptr(shard, entry->shardIntervals) @@ -1840,8 +1840,8 @@ CreateSubscriptions(MultiConnection *sourceConnection, "SET LOCAL citus.enable_ddl_propagation TO OFF;", psprintf( "CREATE USER %s SUPERUSER IN ROLE %s;", - target->subscriptionOwnerName, - GetUserNameFromId(ownerId, false) + quote_identifier(target->subscriptionOwnerName), + quote_identifier(GetUserNameFromId(ownerId, false)) ))); StringInfo conninfo = makeStringInfo(); @@ -1885,8 +1885,8 @@ CreateSubscriptions(MultiConnection *sourceConnection, pfree(createSubscriptionCommand); ExecuteCriticalRemoteCommand(target->superuserConnection, psprintf( "ALTER SUBSCRIPTION %s OWNER TO %s", - target->subscriptionName, - target->subscriptionOwnerName + quote_identifier(target->subscriptionName), + quote_identifier(target->subscriptionOwnerName) )); /* @@ -1899,7 +1899,7 @@ CreateSubscriptions(MultiConnection *sourceConnection, "SET LOCAL citus.enable_ddl_propagation TO OFF;", psprintf( "ALTER ROLE %s NOSUPERUSER;", - target->subscriptionOwnerName + quote_identifier(target->subscriptionOwnerName) ))); } }