Re: [PATCH] Fix ALTER SYSTEM empty string bug for GUC_LIST_QUOTE parameters

From: Andrei Klychkov <andrew(dot)a(dot)klychkov(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: [PATCH] Fix ALTER SYSTEM empty string bug for GUC_LIST_QUOTE parameters
Date: 2025-09-04 07:41:50
Message-ID: CA+mfrmwJgd3N1Lcqy64Fi6R+JHAT=bhf6rdh52hMRH78pBM5mQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Even with this patch, an empty string set via SET is still quoted. For
example:
>
> =# SET local_preload_libraries TO '';
> SET
> =# SHOW local_preload_libraries ;
> local_preload_libraries
> -------------------------
> ""
> (1 row)
>
> Is this behavior acceptable? I was thinking that an empty string should
not
> be quoted, regardless of whether it's set by ALTER SYSTEM SET or SET.
> Thought?
>
> If we agree it should be handled in both cases,
flatten_set_variable_args()
> seems to need to be updated.

Hello Fujii,
Thanks for your review!

I'm personally not sure because this is my first patch and I'm trying to
solve a specific issue of the postgresql.auto.conf-related server crashes.
If what your *broader-impact* suggestion makes sense to more experienced
devs in this area, I'd be happy to update the patch as you put it, test it
(as much as I can), and re-submit v3.
Otherwise, I'd be happy with the v2 implementation that seemingly solves my
specific issue.

Thanks
Regards
Andrew

On Wed, Sep 3, 2025 at 4:48 PM Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:

> On Wed, Sep 3, 2025 at 6:59 PM Andrei Klychkov
> <andrew(dot)a(dot)klychkov(at)gmail(dot)com> wrote:
> >
> > Hi Jim,
> >
> > Thanks a lot for reviewing! Nice catch, TIL!
> > Version 2 of the patch is attached, please check it out.
> > In a nutshell, the issue actually wasn't in the
> flatten_set_variable_args() function as initially suspected, but rather in
> the configuration file writing logic in the write_auto_conf_file(): more
> details in v2_README.md
>
> Even with this patch, an empty string set via SET is still quoted. For
> example:
>
> =# SET local_preload_libraries TO '';
> SET
> =# SHOW local_preload_libraries ;
> local_preload_libraries
> -------------------------
> ""
> (1 row)
>
> Is this behavior acceptable? I was thinking that an empty string should not
> be quoted, regardless of whether it's set by ALTER SYSTEM SET or SET.
> Thought?
>
> If we agree it should be handled in both cases, flatten_set_variable_args()
> seems to need to be updated. For example:
>
> @@ -289,7 +289,8 @@ flatten_set_variable_args(const char *name, List *args)
> * Plain string literal or
> identifier. For quote mode,
> * quote it if it's not a
> vanilla identifier.
> */
> - if (flags & GUC_LIST_QUOTE)
> + if (flags & GUC_LIST_QUOTE &&
> + !(val[0] == '\0' &&
> list_length(args) == 1))
>
> appendStringInfoString(&buf, quote_identifier(val));
> else
>
> appendStringInfoString(&buf, val);
>
> Regards,
>
> --
> Fujii Masao
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Rider 2025-09-04 07:49:19 Re: 回复: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c
Previous Message Steven Niu 2025-09-04 07:38:41 Re: 回复: Fix segfault while accessing half-initialized hash table in pgstat_shmem.c