Fix START_REPLICATION failure with publication names containing backslashes

Started by vignesh C12 months ago2 messageshackers

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
1 day ago

@global #bug

#bug
Jump to latest
#1vignesh C
vignesh21@gmail.com

Hi,

While reviewing another patch, I noticed that START_REPLICATION fails
to parse publication names that contain backslash characters (e.g. \0,
\n), even though such names are perfectly valid when used with CREATE
PUBLICATION. This can be reproduced with the following:
CREATE PUBLICATION "regress_pub_\0\n";
CREATE SUBSCRIPTION regress_sub CONNECTION 'dbname=postgres
host=localhost port=5432' PUBLICATION "regress_pub_\0\n";

CREATE PUBLICATION allows quoted identifiers that may include
backslashes. However, when the subscriber sends such a publication
name back to the walsender as part of START_REPLICATION, the
replication grammar rejects it and throws a syntax error. This happens
because the publication name is passed through escape string
processing before being sent, even though the replication grammar does
not accept escape string forms. The attached patch removes the
unnecessary escape-string handling and passes the publication name as
it is. Replication grammar does not require escape string processing
here, and sending the raw identifier ensures consistent behaviour
between CREATE PUBLICATION and START_REPLICATION.

Regards,
Vignesh

Attachments:

t52801_1
0001-Fix-START_REPLICATION-failure-when-publication-names.patchapplication/octet-stream; name=0001-Fix-START_REPLICATION-failure-when-publication-names.patchDownload+25-13
#2Zhijie Hou (Fujitsu)
houzj.fnst@fujitsu.com
In reply to: vignesh C (#1)
RE: Fix START_REPLICATION failure with publication names containing backslashes

On Wednesday, December 3, 2025 5:51 PM vignesh C <vignesh21@gmail.com> wrote:

Hi,

While reviewing another patch, I noticed that START_REPLICATION fails
to parse publication names that contain backslash characters (e.g. \0,
\n), even though such names are perfectly valid when used with CREATE
PUBLICATION. This can be reproduced with the following:
CREATE PUBLICATION "regress_pub_\0\n";
CREATE SUBSCRIPTION regress_sub CONNECTION 'dbname=postgres
host=localhost port=5432' PUBLICATION "regress_pub_\0\n";

CREATE PUBLICATION allows quoted identifiers that may include
backslashes. However, when the subscriber sends such a publication
name back to the walsender as part of START_REPLICATION, the
replication grammar rejects it and throws a syntax error. This happens
because the publication name is passed through escape string
processing before being sent, even though the replication grammar does
not accept escape string forms. The attached patch removes the
unnecessary escape-string handling and passes the publication name as
it is. Replication grammar does not require escape string processing
here, and sending the raw identifier ensures consistent behaviour
between CREATE PUBLICATION and START_REPLICATION.

IIUC, handling escaped strings is necessary, because if the pubname contains
single quotes like below, then it should be handled by
PQescapeLiteral. After applying your patch, pubname names containing single
quotes will not be handled, causing syntax ERROR.

Pub:
CREATE PUBLICATION \"pub' 'pub\" FOR ALL TABLES;

Sub:
CREATE SUBSCRIPTION sub CONNECTION 'dbname=postgres application_name=sub' PUBLICATION "pub' 'pub"
ERROR: could not start WAL streaming: ERROR: syntax error

Best Regards,
Hou zj