]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
postgres_fdw and dblink should check if backend has MyProcPort
authorPeter Eisentraut <peter@eisentraut.org>
Fri, 8 Aug 2025 17:34:31 +0000 (19:34 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 8 Aug 2025 17:34:31 +0000 (19:34 +0200)
before checking ->has_scram_keys.  MyProcPort is NULL in background
workers.  So this could crash for example if a background worker
accessed a suitable configured foreign table.

Author: Alexander Pyhalov <a.pyhalov@postgrespro.ru>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/27b29a35-9b96-46a9-bc1a-914140869dac%40gmail.com

contrib/dblink/dblink.c
contrib/postgres_fdw/connection.c

index f98805fb5f73500e0bd83960274312abee35345d..0cf4c27f2e967ac31677abf69c1e8e6e7a9b9901 100644 (file)
@@ -2643,7 +2643,7 @@ dblink_connstr_has_required_scram_options(const char *connstr)
                PQconninfoFree(options);
        }
 
-       has_scram_keys = has_scram_client_key && has_scram_server_key && MyProcPort->has_scram_keys;
+       has_scram_keys = has_scram_client_key && has_scram_server_key && MyProcPort != NULL && MyProcPort->has_scram_keys;
 
        return (has_scram_keys && has_require_auth);
 }
@@ -2676,7 +2676,7 @@ dblink_security_check(PGconn *conn, const char *connname, const char *connstr)
         * only added if UseScramPassthrough is set, and the user is not allowed
         * to add the SCRAM keys on fdw and user mapping options.
         */
-       if (MyProcPort->has_scram_keys && dblink_connstr_has_required_scram_options(connstr))
+       if (MyProcPort != NULL && MyProcPort->has_scram_keys && dblink_connstr_has_required_scram_options(connstr))
                return;
 
 #ifdef ENABLE_GSS
@@ -2749,7 +2749,7 @@ dblink_connstr_check(const char *connstr)
        if (dblink_connstr_has_pw(connstr))
                return;
 
-       if (MyProcPort->has_scram_keys && dblink_connstr_has_required_scram_options(connstr))
+       if (MyProcPort != NULL && MyProcPort->has_scram_keys && dblink_connstr_has_required_scram_options(connstr))
                return;
 
 #ifdef ENABLE_GSS
@@ -2896,7 +2896,7 @@ get_connect_string(const char *servername)
                 * the user overwrites these options we can ereport on
                 * dblink_connstr_check and dblink_security_check.
                 */
-               if (MyProcPort->has_scram_keys && UseScramPassthrough(foreign_server, user_mapping))
+               if (MyProcPort != NULL && MyProcPort->has_scram_keys && UseScramPassthrough(foreign_server, user_mapping))
                        appendSCRAMKeysInfo(&buf);
 
                foreach(cell, fdw->options)
index e8148f2c5a223f7e9379f74102ea8d59091d4d1b..4fbb6c182b82c4f0d3dbee6ad1cef64208e12053 100644 (file)
@@ -464,7 +464,7 @@ pgfdw_security_check(const char **keywords, const char **values, UserMapping *us
         * assume that UseScramPassthrough is also true since SCRAM options are
         * only set when UseScramPassthrough is enabled.
         */
-       if (MyProcPort->has_scram_keys && pgfdw_has_required_scram_options(keywords, values))
+       if (MyProcPort != NULL && MyProcPort->has_scram_keys && pgfdw_has_required_scram_options(keywords, values))
                return;
 
        ereport(ERROR,
@@ -570,7 +570,7 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
                n++;
 
                /* Add required SCRAM pass-through connection options if it's enabled. */
-               if (MyProcPort->has_scram_keys && UseScramPassthrough(server, user))
+               if (MyProcPort != NULL && MyProcPort->has_scram_keys && UseScramPassthrough(server, user))
                {
                        int                     len;
                        int                     encoded_len;
@@ -748,7 +748,7 @@ check_conn_params(const char **keywords, const char **values, UserMapping *user)
         * assume that UseScramPassthrough is also true since SCRAM options are
         * only set when UseScramPassthrough is enabled.
         */
-       if (MyProcPort->has_scram_keys && pgfdw_has_required_scram_options(keywords, values))
+       if (MyProcPort != NULL && MyProcPort->has_scram_keys && pgfdw_has_required_scram_options(keywords, values))
                return;
 
        ereport(ERROR,
@@ -2559,7 +2559,7 @@ pgfdw_has_required_scram_options(const char **keywords, const char **values)
                }
        }
 
-       has_scram_keys = has_scram_client_key && has_scram_server_key && MyProcPort->has_scram_keys;
+       has_scram_keys = has_scram_client_key && has_scram_server_key && MyProcPort != NULL && MyProcPort->has_scram_keys;
 
        return (has_scram_keys && has_require_auth);
 }