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 c2b4087ff0)
release-11.0-aykut
Jelte Fennema 2023-01-06 15:12:03 +01:00 committed by Jelte Fennema
parent be8cd00d3f
commit 5729f9e690
1 changed files with 8 additions and 6 deletions

View File

@ -1425,7 +1425,7 @@ CreateShardMovePublications(MultiConnection *connection, List *shardList,
bool prefixWithComma = false;
appendStringInfo(createPublicationCommand, "CREATE PUBLICATION %s FOR TABLE ",
ShardMovePublicationName(ownerId));
quote_identifier(ShardMovePublicationName(ownerId)));
ShardInterval *shard = NULL;
foreach_ptr(shard, shardList)
@ -1484,8 +1484,8 @@ CreateShardMoveSubscriptions(MultiConnection *connection, char *sourceNodeName,
"SET LOCAL citus.enable_ddl_propagation TO OFF;",
psprintf(
"CREATE USER %s SUPERUSER IN ROLE %s",
ShardMoveSubscriptionRole(ownerId),
GetUserNameFromId(ownerId, false)
quote_identifier(ShardMoveSubscriptionRole(ownerId)),
quote_identifier(GetUserNameFromId(ownerId, false))
)));
appendStringInfo(conninfo, "host='%s' port=%d user='%s' dbname='%s' "
@ -1505,8 +1505,10 @@ CreateShardMoveSubscriptions(MultiConnection *connection, char *sourceNodeName,
pfree(createSubscriptionCommand);
ExecuteCriticalRemoteCommand(connection, psprintf(
"ALTER SUBSCRIPTION %s OWNER TO %s",
ShardMoveSubscriptionName(ownerId),
ShardMoveSubscriptionRole(ownerId)
quote_identifier(ShardMoveSubscriptionName(
ownerId)),
quote_identifier(ShardMoveSubscriptionRole(
ownerId))
));
/*
@ -1519,7 +1521,7 @@ CreateShardMoveSubscriptions(MultiConnection *connection, char *sourceNodeName,
"SET LOCAL citus.enable_ddl_propagation TO OFF;",
psprintf(
"ALTER ROLE %s NOSUPERUSER",
ShardMoveSubscriptionRole(ownerId)
quote_identifier(ShardMoveSubscriptionRole(ownerId))
)));
ExecuteCriticalRemoteCommand(connection, psprintf(