From b8a269fdbc75e8d23c71433a5823f5fd24d9b5e5 Mon Sep 17 00:00:00 2001 From: Sunil Seetharama Date: Wed, 24 Dec 2025 16:10:44 +0530 Subject: [PATCH] Fix missing pstrdup() before SplitIdentifierString() calls SplitIdentifierString() modifies the input string in-place and returns a list of pointers into that string. The function's contract requires that the caller provide a modifiable copy of the string. Two call sites were passing strings directly from DefElem nodes without first making a copy: 1. parse_publication_options() in publicationcmds.c passed the result of defGetString() directly, which returns a pointer into the DefElem. 2. pgoutput_startup() in pgoutput.c passed strVal(defel->arg) directly. While these worked in practice because the parsed results were used immediately and the DefElem nodes remained valid, this violated the API contract and could lead to subtle bugs if the code were modified to use the results after the DefElem nodes were freed. --- src/backend/commands/publicationcmds.c | 2 +- src/backend/replication/pgoutput/pgoutput.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/commands/publicationcmds.c b/src/backend/commands/publicationcmds.c index 40a4efd7390..6408b112a90 100644 --- a/src/backend/commands/publicationcmds.c +++ b/src/backend/commands/publicationcmds.c @@ -121,7 +121,7 @@ parse_publication_options(ParseState *pstate, pubactions->pubtruncate = false; *publish_given = true; - publish = defGetString(defel); + publish = pstrdup(defGetString(defel)); if (!SplitIdentifierString(publish, ',', &publish_list)) ereport(ERROR, diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c index 787998abb8a..3a120bcbd92 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -346,7 +346,7 @@ parse_output_parameters(List *options, PGOutputData *data) errmsg("conflicting or redundant options"))); publication_names_given = true; - if (!SplitIdentifierString(strVal(defel->arg), ',', + if (!SplitIdentifierString(pstrdup(strVal(defel->arg)), ',', &data->publication_names)) ereport(ERROR, (errcode(ERRCODE_INVALID_NAME), -- 2.50.1