]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix issue with EVENT TRIGGERS and ALTER PUBLICATION
authorDavid Rowley <drowley@postgresql.org>
Tue, 6 Jan 2026 04:30:32 +0000 (17:30 +1300)
committerDavid Rowley <drowley@postgresql.org>
Tue, 6 Jan 2026 04:30:32 +0000 (17:30 +1300)
When processing the "publish" options of an ALTER PUBLICATION command,
we call SplitIdentifierString() to split the options into a List of
strings.  Since SplitIdentifierString() modifies the delimiter
character and puts NULs in their place, this would overwrite the memory
of the AlterPublicationStmt.  Later in AlterPublicationOptions(), the
modified AlterPublicationStmt is copied for event triggers, which would
result in the event trigger only seeing the first "publish" option
rather than all options that were specified in the command.

To fix this, make a copy of the string before passing to
SplitIdentifierString().

Here we also adjust a similar case in the pgoutput plugin.  There's no
known issues caused by SplitIdentifierString() here, so this is being
done out of paranoia.

Thanks to Henson Choi for putting together an example case showing the
ALTER PUBLICATION issue.

Author: sunil s <sunilfeb26@gmail.com>
Reviewed-by: Henson Choi <assam258@gmail.com>
Reviewed-by: zengman <zengman@halodbtech.com>
Backpatch-through: 14

src/backend/commands/publicationcmds.c
src/backend/replication/pgoutput/pgoutput.c

index f4ba572697a263078cb9e3e09a56298c637ce540..874a8ce6e143730e7f2720e474acc72ac4affdd8 100644 (file)
@@ -123,7 +123,12 @@ parse_publication_options(ParseState *pstate,
                        pubactions->pubtruncate = false;
 
                        *publish_given = true;
-                       publish = defGetString(defel);
+
+                       /*
+                        * SplitIdentifierString destructively modifies its input, so make
+                        * a copy so we don't modify the memory of the executing statement
+                        */
+                       publish = pstrdup(defGetString(defel));
 
                        if (!SplitIdentifierString(publish, ',', &publish_list))
                                ereport(ERROR,
index 62e584a2cd10f2c7335e16b20b2a844cc2f048ff..210d49a222867659bb8b1c6c774b8f70b33cca97 100644 (file)
@@ -340,7 +340,11 @@ parse_output_parameters(List *options, PGOutputData *data)
                                                 errmsg("conflicting or redundant options")));
                        publication_names_given = true;
 
-                       if (!SplitIdentifierString(strVal(defel->arg), ',',
+                       /*
+                        * Pass a copy of the DefElem->arg since SplitIdentifierString
+                        * modifies its input.
+                        */
+                       if (!SplitIdentifierString(pstrdup(strVal(defel->arg)), ',',
                                                                           &data->publication_names))
                                ereport(ERROR,
                                                (errcode(ERRCODE_INVALID_NAME),