Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit dabda64

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 168a809 commit dabda64

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

contrib/dblink/dblink.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ static void materializeQueryResult(FunctionCallInfo fcinfo,
9494
const char *conname,
9595
const char *sql,
9696
bool fail);
97-
static PGresult *storeQueryResult(storeInfo *sinfo, PGconn *conn, const char *sql);
98-
static void storeRow(storeInfo *sinfo, PGresult *res, bool first);
97+
static PGresult *storeQueryResult(volatile storeInfo *sinfo, PGconn *conn, const char *sql);
98+
static void storeRow(volatile storeInfo *sinfo, PGresult *res, bool first);
9999
static remoteConn *getConnectionByName(const char *name);
100100
static HTAB *createConnHash(void);
101101
static void createNewConnection(const char *name, remoteConn *rconn);
@@ -966,13 +966,13 @@ materializeQueryResult(FunctionCallInfo fcinfo,
966966
{
967967
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
968968
PGresult *volatile res = NULL;
969-
storeInfo sinfo;
969+
volatile storeInfo sinfo;
970970

971971
/* prepTuplestoreResult must have been called previously */
972972
Assert(rsinfo->returnMode == SFRM_Materialize);
973973

974974
/* initialize storeInfo to empty */
975-
memset(&sinfo, 0, sizeof(sinfo));
975+
memset((void *) &sinfo, 0, sizeof(sinfo));
976976
sinfo.fcinfo = fcinfo;
977977

978978
PG_TRY();
@@ -1077,7 +1077,7 @@ materializeQueryResult(FunctionCallInfo fcinfo,
10771077
* Execute query, and send any result rows to sinfo->tuplestore.
10781078
*/
10791079
static PGresult *
1080-
storeQueryResult(storeInfo *sinfo, PGconn *conn, const char *sql)
1080+
storeQueryResult(volatile storeInfo *sinfo, PGconn *conn, const char *sql)
10811081
{
10821082
bool first = true;
10831083
int nestlevel = -1;
@@ -1145,7 +1145,7 @@ storeQueryResult(storeInfo *sinfo, PGconn *conn, const char *sql)
11451145
* (in this case the PGresult might contain either zero or one row).
11461146
*/
11471147
static void
1148-
storeRow(storeInfo *sinfo, PGresult *res, bool first)
1148+
storeRow(volatile storeInfo *sinfo, PGresult *res, bool first)
11491149
{
11501150
int nfields = PQnfields(res);
11511151
HeapTuple tuple;

0 commit comments

Comments
 (0)