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.1-jelte
Jelte Fennema 2023-01-06 15:12:03 +01:00 committed by Jelte Fennema
parent c70cf963c4
commit ebd9964b99
1 changed files with 6 additions and 6 deletions

View File

@ -1674,7 +1674,7 @@ CreatePublications(MultiConnection *connection,
bool prefixWithComma = false; bool prefixWithComma = false;
appendStringInfo(createPublicationCommand, "CREATE PUBLICATION %s FOR TABLE ", appendStringInfo(createPublicationCommand, "CREATE PUBLICATION %s FOR TABLE ",
entry->name); quote_identifier(entry->name));
ShardInterval *shard = NULL; ShardInterval *shard = NULL;
foreach_ptr(shard, entry->shardIntervals) foreach_ptr(shard, entry->shardIntervals)
@ -1840,8 +1840,8 @@ CreateSubscriptions(MultiConnection *sourceConnection,
"SET LOCAL citus.enable_ddl_propagation TO OFF;", "SET LOCAL citus.enable_ddl_propagation TO OFF;",
psprintf( psprintf(
"CREATE USER %s SUPERUSER IN ROLE %s;", "CREATE USER %s SUPERUSER IN ROLE %s;",
target->subscriptionOwnerName, quote_identifier(target->subscriptionOwnerName),
GetUserNameFromId(ownerId, false) quote_identifier(GetUserNameFromId(ownerId, false))
))); )));
StringInfo conninfo = makeStringInfo(); StringInfo conninfo = makeStringInfo();
@ -1885,8 +1885,8 @@ CreateSubscriptions(MultiConnection *sourceConnection,
pfree(createSubscriptionCommand); pfree(createSubscriptionCommand);
ExecuteCriticalRemoteCommand(target->superuserConnection, psprintf( ExecuteCriticalRemoteCommand(target->superuserConnection, psprintf(
"ALTER SUBSCRIPTION %s OWNER TO %s", "ALTER SUBSCRIPTION %s OWNER TO %s",
target->subscriptionName, quote_identifier(target->subscriptionName),
target->subscriptionOwnerName quote_identifier(target->subscriptionOwnerName)
)); ));
/* /*
@ -1899,7 +1899,7 @@ CreateSubscriptions(MultiConnection *sourceConnection,
"SET LOCAL citus.enable_ddl_propagation TO OFF;", "SET LOCAL citus.enable_ddl_propagation TO OFF;",
psprintf( psprintf(
"ALTER ROLE %s NOSUPERUSER;", "ALTER ROLE %s NOSUPERUSER;",
target->subscriptionOwnerName quote_identifier(target->subscriptionOwnerName)
))); )));
} }
} }