pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Zhijie Hou <houzhijie22@gmail.com>
To: Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com>
Cc: brar@gmx.de <brar@gmx.de>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #19795: pgoutput: walsender crashes on START_REPLICATION option without a value
Date: Sat, 31 Oct 2026 19:32:00 +0800
Message-ID: <9bcab85a-edda-4302-bdd0-1c1cf5b7a66c@gmail.com> (raw )
In-Reply-To: <OS7PR01MB18317FEB9D24DE47C5077EF90F5612@OS7PR01MB18317.jpnprd01.prod.outlook.com >
References: <19795-6d7d506133b7f062@postgresql.org >
<CAFvd2n-BDb2rp+8jKyUrf-Uv4YgZqDa+O0gzt_JDfCpC-9gGxA@mail.gmail.com >
<OS7PR01MB18317FEB9D24DE47C5077EF90F5612@OS7PR01MB18317.jpnprd01.prod.outlook.com >
Hi,
On Mon, Oct 26, 2026 at 10:56 AM "Hayato Kuroda (Fujitsu)" wrote:
>
>> Attached is a patch that uses defGetString() for "proto_version" and
>> "publication_names" and adds a simple test in 030_pg_recvlogical.pl
>> to confirm it works.
>
> Thanks for the patch. One question:
>
> ```
> if (parsed > PG_UINT32_MAX)
> ereport(ERROR,
> (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
> errmsg("proto_version \"%s\" out of range",
> strVal(defel->arg))));
> ```
>
> Here strVal() is still used, but I feel it's better to refer `val` here. We can completely remove
> the function call.
Thanks for reviewing.
Here is the V2 patch.
--
Best Regards,
Zhijie Hou
Attachments:
v2-0001-Fix-pgoutput-crash-on-missing-option-values.patch (text/plain, 3.6K) download
From 54068fa3084f7279ce28b1e9c843f716a65a7bb6 Mon Sep 17 00:00:00 2001
From: Zhijie Hou <houzhijie22@gmail.com>
Date: Fri, 30 Oct 2026 12:29:51 +0800
Subject: [PATCH v2] Fix pgoutput crash on missing option values.
The replication protocol allows options without values, but pgoutput
dereferenced a NULL DefElem argument for proto_version and
publication_names. A replication client could therefore crash the
walsender and force the postmaster to restart all sessions.
Fix this by reading both options with defGetString(), which reports a
missing parameter cleanly.
Reported-by: Brar Piening <brar@gmx.de>
Author: Zhijie Hou <houzhijie22@gmail.com>
Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
Discussion: https://postgr.es/m/19795-6d7d506133b7f062@postgresql.org
Backpatch-through: 14
---
src/backend/replication/pgoutput/pgoutput.c | 7 ++--
src/bin/pg_basebackup/t/030_pg_recvlogical.pl | 35 +++++++++++++++++++
2 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index b481d5bb388..c8caa163c15 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -316,7 +316,7 @@ parse_output_parameters(List *options, PGOutputData *data)
{
unsigned long parsed;
char *endptr;
- const char *val = strVal(defel->arg);
+ const char *val = defGetString(defel);
if (protocol_version_given)
ereport(ERROR,
@@ -334,8 +334,7 @@ parse_output_parameters(List *options, PGOutputData *data)
if (parsed > PG_UINT32_MAX)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("proto_version \"%s\" out of range",
- strVal(defel->arg))));
+ errmsg("proto_version \"%s\" out of range", val)));
data->protocol_version = (uint32) parsed;
}
@@ -351,7 +350,7 @@ parse_output_parameters(List *options, PGOutputData *data)
* Pass a copy of the DefElem->arg since SplitIdentifierString
* modifies its input.
*/
- if (!SplitIdentifierString(pstrdup(strVal(defel->arg)), ',',
+ if (!SplitIdentifierString(pstrdup(defGetString(defel)), ',',
&data->publication_names))
ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
diff --git a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
index 07ad07fef2a..309a6c04044 100644
--- a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
+++ b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
@@ -100,6 +100,41 @@ $node->command_ok(
],
'slot dropped');
+# Check that pgoutput rejects options that require a parameter when passed
+# without a value.
+$node->safe_psql('postgres',
+ "SELECT pg_create_logical_replication_slot('pgoutput_slot', 'pgoutput')");
+
+$node->command_fails_like(
+ [
+ 'pg_recvlogical',
+ '--slot' => 'pgoutput_slot',
+ '--dbname' => $node->connstr('postgres'),
+ '--start',
+ '--option' => 'proto_version',
+ '--no-loop',
+ '--file' => '-',
+ ],
+ qr/proto_version requires a parameter/,
+ 'pgoutput proto_version option without a value');
+
+$node->command_fails_like(
+ [
+ 'pg_recvlogical',
+ '--slot' => 'pgoutput_slot',
+ '--dbname' => $node->connstr('postgres'),
+ '--start',
+ '--option' => 'proto_version=1',
+ '--option' => 'publication_names',
+ '--no-loop',
+ '--file' => '-',
+ ],
+ qr/publication_names requires a parameter/,
+ 'pgoutput publication_names option without a value');
+
+$node->safe_psql('postgres',
+ "SELECT pg_drop_replication_slot('pgoutput_slot')");
+
#test with two-phase option enabled
$node->command_ok(
[
--
2.54.0 (Apple Git-157)
view thread (8+ messages) latest in thread
Message-ID: <9bcab85a-edda-4302-bdd0-1c1cf5b7a66c@gmail.com>
Permalink: ../9bcab85a-edda-4302-bdd0-1c1cf5b7a66c@gmail.com/
Also on: postgresql.org/message-id/9bcab85a-edda-4302-bdd0-1c1cf5b7a66c@gmail.com
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: houzhijie22@gmail.com, kuroda.hayato@fujitsu.com, brar@gmx.de
Subject: Re: BUG #19795: pgoutput: walsender crashes on START_REPLICATION option without a value
In-Reply-To: <9bcab85a-edda-4302-bdd0-1c1cf5b7a66c@gmail.com>
References: <19795-6d7d506133b7f062@postgresql.org> <CAFvd2n-BDb2rp+8jKyUrf-Uv4YgZqDa+O0gzt_JDfCpC-9gGxA@mail.gmail.com> <OS7PR01MB18317FEB9D24DE47C5077EF90F5612@OS7PR01MB18317.jpnprd01.prod.outlook.com> <9bcab85a-edda-4302-bdd0-1c1cf5b7a66c@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox