[PATCH] Add a check_hook for output_plugin_libraries
[PATCH] Add a check_hook for output_plugin_libraries
Hi all, Fujii-san noted in [1] that the new output_plugin_libraries GUC doesn't have its syntax validated until it's actually used. This is only a problem if a DBA/superuser makes a mistake, but it would be really annoying for them to hit it, and it contradicts an assumption I made inside the new pg_upgrade check. Attached is a patch to fix that. This isn't ready for backpatching yet, because the new test is added in a place that doesn't exist in some of the older branches. I'll look for a better location, but if anyone has a preference off the bat, let me know. For PG20 onwards, I think it'd be really nice to enforce that all GUC_LIST_QUOTE variables must at least pass SplitGUCList() validation if they don't provide their own explicit check_hook. We have other code and comments implying that clients don't have to worry about this case; an example is in [2]. Thanks, --Jacob [1] https://postgr.es/m/CAHGQGwG81iHN46mY_19Bne5RuKfAjH4dOnQ7-8i%3D7KYJk_0rAg%40mail.gmail.com [2] https://postgr.es/m/CAOYmi%2B%3DTomajOOr3OkshSMrNWERAc9fT1je_TEy6Z1UseNy-hA%40mail.gmail.com
RE: [PATCH] Add a check_hook for output_plugin_libraries
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Dear Jacob, > Fujii-san noted in [1] that the new output_plugin_libraries GUC > doesn't have its syntax validated until it's actually used. This is > only a problem if a DBA/superuser makes a mistake, but it would be > really annoying for them to hit it, and it contradicts an assumption I > made inside the new pg_upgrade check. Attached is a patch to fix that. Thank for the patch. I found that ALTER DATABASE SET command can cause the inconsistent state. Reproducer: ``` postgres=# SHOW output_plugin_libraries ; output_plugin_libraries --------------------------- "pgoutput, test_decoding" (1 row) postgres=# ALTER DATABASE postgres SET output_plugin_libraries TO 'pgoutput, '; ALTER DATABASE postgres=# \c postgres You are now connected to database "postgres" as user "postgres". postgres=# SHOW output_plugin_libraries ; output_plugin_libraries ------------------------- "pgoutput, " (1 row) ``` Per my experiments and analysis, flatten_set_variable_args() added a double-quote at the begining and the end. Then the check-hook calls SplitGUCList(), but it seems to regard the quoted string as a chunk. Do you think this should be fixed? If so SplitGUCList may not be enough, but it may lead additional policy for the plugin name. E.g., plugin should not contain "," in the name. > For PG20 onwards, I think it'd be really nice to enforce that all > GUC_LIST_QUOTE variables must at least pass SplitGUCList() validation > if they don't provide their own explicit check_hook. We have other > code and comments implying that clients don't have to worry about this > case; an example is in [2]. Sounds better, but it may have a same issue as above. Best regards, Hayato Kuroda FUJITSU LIMITED
Re: [PATCH] Add a check_hook for output_plugin_libraries
От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Wed, Sep 23, 2026 at 11:41 PM Hayato Kuroda (Fujitsu) wrote: > Thank for the patch. Thanks for the review! > I found that ALTER DATABASE SET command can > cause the inconsistent state. Reproducer: > > ``` > postgres=# SHOW output_plugin_libraries ; > output_plugin_libraries > --------------------------- > "pgoutput, test_decoding" > (1 row) Where did your double-quotes come from? If they came from a previous `SET output_plugin_libraries = 'pgoutput, test_decoding'`, then that wasn't a correct command; see below. Here's the output on my machine after a fresh initdb: postgres=# show output_plugin_libraries; output_plugin_libraries ------------------------- pgoutput, test_decoding (1 row) > postgres=# ALTER DATABASE postgres SET output_plugin_libraries TO 'pgoutput, '; > ALTER DATABASE > postgres=# \c postgres > You are now connected to database "postgres" as user "postgres". > postgres=# SHOW output_plugin_libraries ; > output_plugin_libraries > ------------------------- > "pgoutput, " > (1 row) This is (unfortunately?) as designed, and it should match the behavior of the other GUC_LIST_QUOTE variables. Quoting 'pgoutput, ' means that you want to use a plugin named "pgoutput, .so" on disk, which you're allowed to do. The correct way to set output_plugin_libraries would be SET output_plugin_libraries = pgoutput, test_decoding; or SET output_plugin_libraries = 'pgoutput', 'test_decoding'; I think that behavior is confusing for people who expect to have to quote the whole thing (including me). But it's presumably tied to how we want search_path to behave for everyone, so changing it would probably be a very big project. Thanks, --Jacob
RE: [PATCH] Add a check_hook for output_plugin_libraries
Dear Jacob, > Where did your double-quotes come from? If they came from a previous > `SET output_plugin_libraries = 'pgoutput, test_decoding'`, then that > wasn't a correct command; see below. Here's the output on my machine > after a fresh initdb: > > postgres=# show output_plugin_libraries; > output_plugin_libraries > ------------------------- > pgoutput, test_decoding > (1 row) You're right. When I ran for the just initialized instance, I got the same. ``` postgres=# SHOW output_plugin_libraries ; output_plugin_libraries ------------------------- pgoutput, test_decoding (1 row) ``` > I think that behavior is confusing for people who expect to have to > quote the whole thing (including me). But it's presumably tied to how > we want search_path to behave for everyone, so changing it would > probably be a very big project. Hmm, okay. I confirmed the same behavior for the search_path. At very least fixing all here is not realistic. Below are my comments: 01. ``` + /* + * XXX SplitGUCList won't respect guc_malloc requirements, but this is + * consistent with other check_hook implementations... + */ ``` Let me clarify: it's because the SplitGUCList()->lappend() can raise OOM error, right? Maybe we need to add another function to handle around here, but it can be in PG20... 02. Is the same check in StartupDecodingContext() still needed? I.e. we can check the returned value by Assert() here. 03. ``` +# check.c assumes the list syntax of output_plugin_libraries is validated by the +# server, so take a moment to confirm that now. (This is difficult to test via +# regression suite, because our SET grammar won't accept the bad syntax.) ``` Per my experiment, an SQL function set_config() is usable. So can't we put in guc.sql? PSA my idea. Best regards, Hayato Kuroda FUJITSU LIMITED
Re: [PATCH] Add a check_hook for output_plugin_libraries
On Thu, Sep 24, 2026 at 7:46 PM Hayato Kuroda (Fujitsu) wrote: > ``` > + /* > + * XXX SplitGUCList won't respect guc_malloc requirements, but this is > + * consistent with other check_hook implementations... > + */ > ``` > > Let me clarify: it's because the SplitGUCList()->lappend() can raise OOM error, > right? Right. > Is the same check in StartupDecodingContext() still needed? I.e. we can check the returned value > by Assert() here. Ah, thanks. I think we should avoid relying on assertions in security-critical code, but I've simplified the dead code path to an elog(ERROR). > +# check.c assumes the list syntax of output_plugin_libraries is validated by the > +# server, so take a moment to confirm that now. (This is difficult to test via > +# regression suite, because our SET grammar won't accept the bad syntax.) > ``` > > Per my experiment, an SQL function set_config() is usable. So can't we put in guc.sql? > PSA my idea. Thank you! I completely forgot about set_config(); that should make backpatching much simpler. I applied your patch with is_local set to true instead of false, so a regression failure won't change state for later tests in the file. v2 attached. Thanks, --Jacob
RE: [PATCH] Add a check_hook for output_plugin_libraries
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Dear Jacob, Thanks for updating the patch. Mostly LGTM, one minor comment. ``` + elog(ERROR, "invalid output_plugin_libraries syntax after check_hook?"); ``` Per my grep, it is rarely happen to put"?" at the end of elog() message. Maybe it's OK to say: invalid list syntax in parameter \"%s\" Best regards, Hayato Kuroda FUJITSU LIMITED
Re: [PATCH] Add a check_hook for output_plugin_libraries
От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Wed, Sep 30, 2026 at 2:39 AM Hayato Kuroda (Fujitsu) wrote: > Thanks for updating the patch. Thanks for the review! This has been backpatched. > Per my grep, it is rarely happen to put"?" at the end of elog() message. We don't seem to have a unified style for can't-happen elog calls, but I changed it to use "internal error:" to make it more clear that someone should tell us if it happens. Thanks, --Jacob
RE: [PATCH] Add a check_hook for output_plugin_libraries
От:
"Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Дата:
Hi Jacob, I confirmed your push, LGTM. > We don't seem to have a unified style for can't-happen elog calls, but > I changed it to use "internal error:" to make it more clear that > someone should tell us if it happens. FYI, I could not find existing "internal error:" prefix in the backend codes, but personally it looks OK. Nobody would see it. I can follow the manner when I will add similar elog(ERROR). Best regards, Hayato Kuroda FUJITSU LIMITED