postgres.git / summary / log / commit / refs
commit e2b3549a4103efeb2fb35daef770427fa8264a17
Author: Jacob Champion <jchampion@postgresql.org>
Date: Fri Nov 06 00:53:48 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 | 46 ++++++++++++++++++++++++-------
src/backend/utils/misc/guc_tables.c | 2 +-
src/include/utils/guc_hooks.h | 2 ++
src/test/regress/expected/guc.out | 4 +++
src/test/regress/sql/guc.sql | 3 ++
5 files changed, 46 insertions(+), 11 deletions(-)
diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c
index 4d3a39f4cd7..09d8b0fa2c5 100644
--- a/src/backend/replication/logical/logical.c
+++ b/src/backend/replication/logical/logical.c
@@ -43,6 +43,7 @@
#include "storage/procarray.h"
#include "utils/builtins.h"
#include "utils/guc.h"
+#include "utils/guc_hooks.h"
#include "utils/injection_point.h"
#include "utils/inval.h"
#include "utils/memutils.h"
@@ -108,6 +109,39 @@ static void update_progress_txn_cb_wrapper(ReorderBuffer *cache,
static void LoadOutputPlugin(OutputPluginCallbacks *callbacks, const char *plugin);
+/* check_hook: validate new output_plugin_libraries value */
+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);
+ guc_free(copy);
+
+ return ok;
+}
+
/*
* Make sure the current settings & environment are capable of doing logical
* decoding.
@@ -203,17 +237,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_ptr(char, allowed, elemlist)
{
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 7cab4c735c2..82f78683032 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -4992,7 +4992,7 @@ struct config_string ConfigureNamesString[] =
},
&output_plugin_libraries_string,
"pgoutput, test_decoding",
- NULL, NULL, NULL
+ check_output_plugin_libraries, NULL, NULL
},
{
diff --git a/src/include/utils/guc_hooks.h b/src/include/utils/guc_hooks.h
index 82ac8646a8d..6dfc5cc3f97 100644
--- a/src/include/utils/guc_hooks.h
+++ b/src/include/utils/guc_hooks.h
@@ -92,6 +92,8 @@ extern bool check_multixact_member_buffers(int *newval, void **extra,
extern bool check_multixact_offset_buffers(int *newval, void **extra,
GucSource source);
extern bool check_notify_buffers(int *newval, void **extra, GucSource source);
+extern bool check_output_plugin_libraries(char **newval, void **extra,
+ GucSource source);
extern bool check_primary_slot_name(char **newval, void **extra,
GucSource source);
extern bool check_random_seed(double *newval, void **extra, GucSource source);
diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out
index 7f9e29c765c..28bbf348bd9 100644
--- a/src/test/regress/expected/guc.out
+++ b/src/test/regress/expected/guc.out
@@ -31,6 +31,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 f65f84a2632..1c616b75e47 100644
--- a/src/test/regress/sql/guc.sql
+++ b/src/test/regress/sql/guc.sql
@@ -12,6 +12,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: c88c71a4b52a]