From c2b4087ff0a95bc8a3fe0b079813224a35bfe002 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. --- .../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 702c91a3b..86b40bfba 100644 --- a/src/backend/distributed/replication/multi_logical_replication.c +++ b/src/backend/distributed/replication/multi_logical_replication.c @@ -1315,7 +1315,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) @@ -1498,8 +1498,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)) ))); InsertCleanupRecordInSubtransaction(CLEANUP_OBJECT_USER, @@ -1554,8 +1554,8 @@ CreateSubscriptions(MultiConnection *sourceConnection, ExecuteCriticalRemoteCommand(target->superuserConnection, psprintf( "ALTER SUBSCRIPTION %s OWNER TO %s", - target->subscriptionName, - target->subscriptionOwnerName + quote_identifier(target->subscriptionName), + quote_identifier(target->subscriptionOwnerName) )); /* @@ -1568,7 +1568,7 @@ CreateSubscriptions(MultiConnection *sourceConnection, "SET LOCAL citus.enable_ddl_propagation TO OFF;", psprintf( "ALTER ROLE %s NOSUPERUSER;", - target->subscriptionOwnerName + quote_identifier(target->subscriptionOwnerName) ))); } }