Skip to content

Commit 8abd0e2

Browse files
committed
Fix volatile-safety issue in dblink's materializeQueryResult().
Some fields of the sinfo struct are modified within PG_TRY and then referenced within PG_CATCH, so as with recent patch to async.c, "volatile" is necessary for strict POSIX compliance; and that propagates to a couple of subroutines as well as materializeQueryResult() itself. I think the risk of actual issues here is probably higher than in async.c, because storeQueryResult() is likely to get inlined into materializeQueryResult(), leaving the compiler free to conclude that its stores into sinfo fields are dead code.
1 parent 3dd084c commit 8abd0e2

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

contrib/dblink/dblink.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ static void materializeQueryResult(FunctionCallInfo fcinfo,
8888
const char *conname,
8989
const char *sql,
9090
bool fail);
91-
static PGresult *storeQueryResult(storeInfo *sinfo, PGconn *conn, const char *sql);
92-
static void storeRow(storeInfo *sinfo, PGresult *res, bool first);
91+
static PGresult *storeQueryResult(volatile storeInfo *sinfo, PGconn *conn, const char *sql);
92+
static void storeRow(volatile storeInfo *sinfo, PGresult *res, bool first);
9393
static remoteConn *getConnectionByName(const char *name);
9494
static HTAB *createConnHash(void);
9595
static void createNewConnection(const char *name, remoteConn *rconn);
@@ -958,13 +958,13 @@ materializeQueryResult(FunctionCallInfo fcinfo,
958958
{
959959
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
960960
PGresult *volatile res = NULL;
961-
storeInfo sinfo;
961+
volatile storeInfo sinfo;
962962

963963
/* prepTuplestoreResult must have been called previously */
964964
Assert(rsinfo->returnMode == SFRM_Materialize);
965965

966966
/* initialize storeInfo to empty */
967-
memset(&sinfo, 0, sizeof(sinfo));
967+
memset((void *) &sinfo, 0, sizeof(sinfo));
968968
sinfo.fcinfo = fcinfo;
969969

970970
PG_TRY();
@@ -1069,7 +1069,7 @@ materializeQueryResult(FunctionCallInfo fcinfo,
10691069
* Execute query, and send any result rows to sinfo->tuplestore.
10701070
*/
10711071
static PGresult *
1072-
storeQueryResult(storeInfo *sinfo, PGconn *conn, const char *sql)
1072+
storeQueryResult(volatile storeInfo *sinfo, PGconn *conn, const char *sql)
10731073
{
10741074
bool first = true;
10751075
int nestlevel = -1;
@@ -1137,7 +1137,7 @@ storeQueryResult(storeInfo *sinfo, PGconn *conn, const char *sql)
11371137
* (in this case the PGresult might contain either zero or one row).
11381138
*/
11391139
static void
1140-
storeRow(storeInfo *sinfo, PGresult *res, bool first)
1140+
storeRow(volatile storeInfo *sinfo, PGresult *res, bool first)
11411141
{
11421142
int nfields = PQnfields(res);
11431143
HeapTuple tuple;

0 commit comments

Comments
 (0)