Initialize dblink remoteConn struct in all cases
authorJoe Conway <mail@joeconway.com>
Thu, 28 May 2020 17:44:54 +0000 (13:44 -0400)
committerJoe Conway <mail@joeconway.com>
Thu, 28 May 2020 17:44:54 +0000 (13:44 -0400)
Two of the members of rconn were left uninitialized. When
dblink_open() is called without an outer transaction it
handles the initialization for us, but with an outer
transaction it does not. Arrange for initialization
in all cases. Backpatch to all supported versions.

Reported-by: Alexander Lakhin
Discussion: https://www.postgresql.org/message-id/flat/9bd0744f-5f04-c778-c5b3-809efe9c30c7%40joeconway.com#c545909a41664991aca60c4d70a10ce7

contrib/dblink/dblink.c

index 2fe5da22b9ae4108cde042b209842e3d0468a70c..736433237c83169d1fb4da59b5a6774c03c4f416 100644 (file)
@@ -298,8 +298,13 @@ dblink_connect(PG_FUNCTION_ARGS)
        conname_or_str = text_to_cstring(PG_GETARG_TEXT_PP(0));
 
    if (connname)
+   {
        rconn = (remoteConn *) MemoryContextAlloc(TopMemoryContext,
                                                  sizeof(remoteConn));
+       rconn->conn = NULL;
+       rconn->openCursorCount = 0;
+       rconn->newXactForCursor = false;
+   }
 
    /* first check for valid foreign data server */
    connstr = get_connect_string(conname_or_str);