Hi Hackers, I'm submitting a patch to fix a bug where ALTER SYSTEM SET with empty strings for GUC_LIST_QUOTE parameters (like shared_preload_libraries) results in malformed configuration entries that cause server crashes on restart.
Please take a look, Thanks Andrew
# Fix for ALTER SYSTEM Empty String Bug ## Problem Description When using `ALTER SYSTEM SET "shared_preload_libraries" TO ''`, PostgreSQL would write a malformed configuration entry to `postgresql.auto.conf`: ``` shared_preload_libraries = '""' ``` This malformed configuration would cause the PostgreSQL server to crash on restart. ## Root Cause The issue occurred in the `flatten_set_variable_args` function in `src/backend/utils/misc/guc_funcs.c`. When a parameter with the `GUC_LIST_QUOTE` flag (like `shared_preload_libraries`) was set to an empty string, the function would call `quote_identifier("")` which returns `""` (double quotes around an empty string). This resulted in the malformed configuration entry. ## Solution The fix modifies the `flatten_set_variable_args` function to check if the value is an empty string before applying the `GUC_LIST_QUOTE` logic. Empty strings are treated as "no value" rather than literal empty strings, so they are not quoted. ## Code Changes In `src/backend/utils/misc/guc_funcs.c`, line 291: ```c - if (flags & GUC_LIST_QUOTE) + if ((flags & GUC_LIST_QUOTE) && val[0] != '\0') ``` ## Testing The fix can be tested by: 1. Running `ALTER SYSTEM SET "shared_preload_libraries" TO ''` 2. Checking that `postgresql.auto.conf` does not contain malformed entries 3. Restarting PostgreSQL to verify no crashes occur ## Affected Parameters This fix affects all GUC parameters that have the `GUC_LIST_QUOTE` flag set, including: - `shared_preload_libraries` - Any other list-type parameters that use quote mode
From 3a6a7db602036309fbc6a7f5c7c731a71038967b Mon Sep 17 00:00:00 2001 From: Andrew Klychkov <andrew.a.klych...@gmail.com> Date: Thu, 28 Aug 2025 10:33:42 +0200 Subject: [PATCH] Fix ALTER SYSTEM empty string bug for GUC_LIST_QUOTE parameters When ALTER SYSTEM SET is used with an empty string for parameters with GUC_LIST_QUOTE flag (like shared_preload_libraries), the empty string was being quoted by quote_identifier(), resulting in '' being written to postgresql.auto.conf. This caused server crashes on restart. The fix prevents empty strings from being quoted when GUC_LIST_QUOTE is set, treating them as 'no value' rather than literal empty strings. Fixes bug where 'ALTER SYSTEM SET "shared_preload_libraries" TO ''' would write 'shared_preload_libraries = '""'' to postgresql.auto.conf. --- src/backend/utils/misc/guc_funcs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/utils/misc/guc_funcs.c b/src/backend/utils/misc/guc_funcs.c index b9e26982ab..389841a4ec 100644 --- a/src/backend/utils/misc/guc_funcs.c +++ b/src/backend/utils/misc/guc_funcs.c @@ -288,8 +288,10 @@ 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. + * However, empty strings should not be quoted as they + * represent "no value" rather than a literal empty string. */ - if (flags & GUC_LIST_QUOTE) + if ((flags & GUC_LIST_QUOTE) && val[0] != '\0') appendStringInfoString(&buf, quote_identifier(val)); else appendStringInfoString(&buf, val); -- 2.47.0