postgres.git / summary / log / commit / refs

commit    d0571ca1609e4cb6c9d31c7137b67e4002641fa6
Author:   Jacob Champion <jchampion@postgresql.org>
Date:     Fri Nov 06 00:54:46 2026 +0000
First released in: 14.25, 15.20, 16.16, 17.12, 18.7, 19.0

    Add a check_hook for output_plugin_libraries
    
    I omitted explicit syntax validation of output_plugin_libraries in
    226e49cbed. [ALTER SYSTEM] SET does this implicitly due to the parser
    grammar, but a DBA could still accidentally put a bad value into
    postgresql.conf, and a superuser could do the same with connection
    options or set_config(). Logical replication would then fail later on.
    
    This is an annoying papercut for a security option to have, so reject
    these cases immediately in a check_hook.
    
    Tests by Hayato Kuroda.
    
    Co-authored-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
    Reported-by: Fujii Masao <masao.fujii@gmail.com>
    Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com>
    Discussion: https://postgr.es/m/CAOYmi%2BkBsG5rNRb1j2VjgTKg8HY90e7vSvZPLeouiAc6nXP9XA%40mail.gmail.com
    Backpatch-through: 14


src/backend/replication/logical/logical.c | 12 ++--------- src/backend/utils/misc/guc.c | 35 ++++++++++++++++++++++++++++++- src/test/regress/expected/guc.out | 4 ++++ src/test/regress/sql/guc.sql | 3 +++ 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c index d796abbde78..db67437ab46 100644 --- a/src/backend/replication/logical/logical.c +++ b/src/backend/replication/logical/logical.c @@ -198,17 +198,9 @@ StartupDecodingContext(List *output_plugin_options, /* Need a modifiable copy */ rawstring = pstrdup(output_plugin_libraries_string); + /* The check_hook should have already handled syntax errors. */ if (!SplitGUCList(rawstring, ',', &elemlist)) - { - /* syntax error in list */ - ereport(LOG, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("invalid list syntax in parameter \"%s\"", - "output_plugin_libraries"))); - - list_free(elemlist); - elemlist = NIL; - } + elog(ERROR, "internal error: invalid output_plugin_libraries syntax after check_hook"); foreach(lc, elemlist) { diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 6225fe78a20..50df9dd7c35 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -243,6 +243,7 @@ static bool check_recovery_target_lsn(char **newval, void **extra, GucSource sou static void assign_recovery_target_lsn(const char *newval, void *extra); static bool check_primary_slot_name(char **newval, void **extra, GucSource source); static bool check_default_with_oids(bool *newval, void **extra, GucSource source); +static bool check_output_plugin_libraries(char **newval, void **extra, GucSource source); /* Private functions in guc-file.l that need to be called from guc.c */ static ConfigVariable *ProcessConfigFileInternal(GucContext context, @@ -4732,7 +4733,7 @@ static struct config_string ConfigureNamesString[] = }, &output_plugin_libraries_string, "pgoutput, test_decoding", - NULL, NULL, NULL + check_output_plugin_libraries, NULL, NULL }, /* End-of-list marker */ @@ -13089,4 +13090,36 @@ check_default_with_oids(bool *newval, void **extra, GucSource source) return true; } +static bool +check_output_plugin_libraries(char **newval, void **extra, GucSource source) +{ + char *copy; + List *components; + bool ok = true; + + copy = guc_strdup(LOG, *newval); + if (!copy) + return false; + + /* + * XXX SplitGUCList won't respect guc_malloc requirements, but this is + * consistent with other check_hook implementations... + */ + if (!SplitGUCList(copy, ',', &components)) + { + GUC_check_errdetail("List syntax is invalid."); + ok = false; + } + + /* + * Like with related GUC_LIST_QUOTE variables, we check only syntax here + * and not the existence of the plugins themselves. + */ + + list_free(components); + free(copy); + + return ok; +} + #include "guc-file.c" diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out index b1ea04181c6..4ae544390db 100644 --- a/src/test/regress/expected/guc.out +++ b/src/test/regress/expected/guc.out @@ -27,6 +27,10 @@ SELECT '2006-08-13 12:34:56'::timestamptz; 2006-08-13 12:34:56-07 (1 row) +-- Check syntax validation of output_plugin_libraries +SELECT set_config('output_plugin_libraries', 'pgoutput,', true); +ERROR: invalid value for parameter "output_plugin_libraries": "pgoutput," +DETAIL: List syntax is invalid. -- SET LOCAL has no effect outside of a transaction SET LOCAL vacuum_cost_delay TO 50; WARNING: SET LOCAL can only be used in transaction blocks diff --git a/src/test/regress/sql/guc.sql b/src/test/regress/sql/guc.sql index 23cd8a1c92c..60688234a38 100644 --- a/src/test/regress/sql/guc.sql +++ b/src/test/regress/sql/guc.sql @@ -9,6 +9,9 @@ SHOW vacuum_cost_delay; SHOW datestyle; SELECT '2006-08-13 12:34:56'::timestamptz; +-- Check syntax validation of output_plugin_libraries +SELECT set_config('output_plugin_libraries', 'pgoutput,', true); + -- SET LOCAL has no effect outside of a transaction SET LOCAL vacuum_cost_delay TO 50; SHOW vacuum_cost_delay; [parent: 10686da4eddb]