postgres.git / summary / log / commit / refs

commit    35848657c67df5bef80f98e0d7091c23ce1e187a
Author:   Michael Paquier <michael@paquier.xyz>
Date:     Sun Nov 01 23:12:53 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 | 8 +++--- src/bin/pg_basebackup/t/030_pg_recvlogical.pl | 35 ++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/backend/replication/pgoutput/pgoutput.c b/src/backend/replication/pgoutput/pgoutput.c index e7b85fcdddf..fd5ed211be6 100644 --- a/src/backend/replication/pgoutput/pgoutput.c +++ b/src/backend/replication/pgoutput/pgoutput.c @@ -192,6 +192,7 @@ parse_output_parameters(List *options, PGOutputData *data) if (strcmp(defel->defname, "proto_version") == 0) { int64 parsed; + const char *val = defGetString(defel); if (protocol_version_given) ereport(ERROR, @@ -199,7 +200,7 @@ parse_output_parameters(List *options, PGOutputData *data) errmsg("conflicting or redundant options"))); protocol_version_given = true; - if (!scanint8(strVal(defel->arg), true, &parsed)) + if (!scanint8(val, true, &parsed)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid proto_version"))); @@ -207,8 +208,7 @@ parse_output_parameters(List *options, PGOutputData *data) if (parsed > PG_UINT32_MAX || parsed < 0) 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; } @@ -224,7 +224,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 53f41814b0b..a78a85e75f9 100644 --- a/src/bin/pg_basebackup/t/030_pg_recvlogical.pl +++ b/src/bin/pg_basebackup/t/030_pg_recvlogical.pl @@ -5,7 +5,7 @@ use strict; use warnings; use TestLib; use PostgresNode; -use Test::More tests => 15; +use Test::More tests => 17; program_help_ok('pg_recvlogical'); program_version_ok('pg_recvlogical'); @@ -63,3 +63,36 @@ $node->command_ok( '--start', '--endpos', "$nextlsn", '--no-loop', '-f', '-' ], 'replayed a transaction'); + +# 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( + [ + 'pg_recvlogical', + '--slot' => 'pgoutput_slot', + '--dbname' => $node->connstr('postgres'), + '--start', + '--option' => 'proto_version', + '--no-loop', + '--file' => '-', + ], + 'pgoutput proto_version option without a value'); + +$node->command_fails( + [ + 'pg_recvlogical', + '--slot' => 'pgoutput_slot', + '--dbname' => $node->connstr('postgres'), + '--start', + '--option' => 'proto_version=1', + '--option' => 'publication_names', + '--no-loop', + '--file' => '-', + ], + 'pgoutput publication_names option without a value'); + +$node->safe_psql('postgres', + "SELECT pg_drop_replication_slot('pgoutput_slot')"); [parent: 275ad2006df5]