From cf766ea59614e3c72a698e4f6dc4cd919da1b0d5 Mon Sep 17 00:00:00 2001 From: Yuriy Grigoryev Date: Mon, 14 Sep 2026 15:31:22 +0700 Subject: [PATCH] Fix postmaster crash on whitespace-only oauth_validator_libraries check_oauth_validator() rejects an unset validator list by looking at the raw GUC string, which does not cover a value made up of whitespace only. SplitDirectoriesString() accepts such a value and hands back an empty list, so when the HBA line carries no validator= option the code went on to read elemlist->length and dereferenced NIL. Every entry point into HBA parsing is affected. load_hba() runs in the postmaster at startup and again on SIGHUP, so reloading a running server brings the whole instance down along with every session on it, and pg_hba_file_rules() parses the file from a regular backend, where the same crash forces a cluster-wide restart. Check the parse result instead of the raw string, keeping the message the empty setting already produced. Add a test that reloads a whitespace-only setting and verifies that the server reports the error and stays up. --- src/backend/libpq/auth-oauth.c | 31 +++++++++++-------- .../modules/oauth_validator/t/001_server.pl | 16 ++++++++++ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/backend/libpq/auth-oauth.c b/src/backend/libpq/auth-oauth.c index b769931..8dfe5f9 100644 --- a/src/backend/libpq/auth-oauth.c +++ b/src/backend/libpq/auth-oauth.c @@ -863,19 +863,6 @@ check_oauth_validator(HbaLine *hbaline, int elevel, char **err_msg) *err_msg = NULL; - if (oauth_validator_libraries_string[0] == '\0') - { - ereport(elevel, - errcode(ERRCODE_CONFIG_FILE_ERROR), - errmsg("parameter \"%s\" must be set for authentication method \"%s\"", - "oauth_validator_libraries", "oauth"), - errcontext("line %d of configuration file \"%s\"", - line_num, file_name)); - *err_msg = psprintf("parameter \"%s\" must be set for authentication method \"%s\"", - "oauth_validator_libraries", "oauth"); - return false; - } - /* SplitDirectoriesString needs a modifiable copy */ rawstring = pstrdup(oauth_validator_libraries_string); @@ -891,6 +878,24 @@ check_oauth_validator(HbaLine *hbaline, int elevel, char **err_msg) goto done; } + /* + * An empty or all-whitespace setting is accepted by + * SplitDirectoriesString(), which returns an empty list for it, so the + * parse result has to be checked rather than the raw string. + */ + if (elemlist == NIL) + { + ereport(elevel, + errcode(ERRCODE_CONFIG_FILE_ERROR), + errmsg("parameter \"%s\" must be set for authentication method \"%s\"", + "oauth_validator_libraries", "oauth"), + errcontext("line %d of configuration file \"%s\"", + line_num, file_name)); + *err_msg = psprintf("parameter \"%s\" must be set for authentication method \"%s\"", + "oauth_validator_libraries", "oauth"); + goto done; + } + if (!hbaline->oauth_validator) { if (elemlist->length == 1) diff --git a/src/test/modules/oauth_validator/t/001_server.pl b/src/test/modules/oauth_validator/t/001_server.pl index 8941a35..86307be 100644 --- a/src/test/modules/oauth_validator/t/001_server.pl +++ b/src/test/modules/oauth_validator/t/001_server.pl @@ -120,6 +120,22 @@ local all testparam oauth issuer="$issuer/param" scope="openid postgres" }); $node->reload; +$log_start = + $node->wait_for_log(qr/reloading configuration files/, $log_start); + +# An all-whitespace library list parses as an empty list. Reject it without +# crashing the postmaster during HBA reload. +$node->append_conf('postgresql.conf', + "oauth_validator_libraries = ' '\n"); +$node->reload; +$log_start = $node->wait_for_log( + qr/parameter "oauth_validator_libraries" must be set/, $log_start); +is($bgconn->query_safe('SELECT 1'), '1', + 'postmaster survives an empty OAuth validator list on reload'); + +$node->append_conf('postgresql.conf', + "oauth_validator_libraries = 'validator'\n"); +$node->reload; $log_start = $node->wait_for_log(qr/reloading configuration files/, $log_start); -- 2.39.5 (Apple Git-154)