postgres.git / summary / log / commit / refs
commit c6cb792e8197df05883d9fcd8725d1a2491ed06e
Author: Michael Paquier <michael@paquier.xyz>
Date: Sun Nov 01 23:12:50 2026 +0000
First released in: 14.25, 15.20, 16.16, 17.12, 18.7, 19.0
Fix pgoutput crash on missing option values
The replication protocol allows options without values, but pgoutput
dereferenced a NULL DefElem argument for parameters proto_version and
publication_names. A replication client was able to crash a WAL sender.
This issue is fixed by reading both options with defGetString(), which
is able to report 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 | 10 ++++----
src/bin/pg_basebackup/t/030_pg_recvlogical.pl | 35 +++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c
index bd9b21d8b21..71a168ceae8 100644
--- a/src/backend/replication/pgoutput/pgoutput.c
+++ b/src/backend/replication/pgoutput/pgoutput.c
@@ -312,6 +312,7 @@ parse_output_parameters(List *options, PGOutputData *data)
{
unsigned long parsed;
char *endptr;
+ const char *val = defGetString(defel);
if (protocol_version_given)
ereport(ERROR,
@@ -320,8 +321,8 @@ parse_output_parameters(List *options, PGOutputData *data)
protocol_version_given = true;
errno = 0;
- parsed = strtoul(strVal(defel->arg), &endptr, 10);
- if (errno != 0 || *endptr != '\0')
+ parsed = strtoul(val, &endptr, 10);
+ if (endptr == val || errno != 0 || *endptr != '\0')
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("invalid proto_version")));
@@ -329,8 +330,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;
}
@@ -346,7 +346,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 38576c2e008..3696ad95734 100644
--- a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
+++ b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl
@@ -73,6 +73,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(
[
[parent: bb0615c890e2]