From 38f25020e3a4ee8a8db814131a1f0d01310c1f40 Mon Sep 17 00:00:00 2001 From: Jason Petersen Date: Tue, 30 May 2017 12:19:27 -0600 Subject: [PATCH] Address PostgreSQL 10's planned stmt changes PostgreSQL appears to now stash the PlannedStmt somewhere within ProcessUtility itself (per Marco), which results in a use-after-free bug if we keep our old behavior of overriding the PlannedStmt's utility statement with a copy with baked-in schema names. The quickest fix is to just avoid this behavior altogether for PostgreSQL 10. Because this area of code needs some attention anyhow (i.e. we're not always doing the right things wrt schema name lookups for our utility statements), Marco suggested this fix until we get to a more comprehensive correction covering other utility commands. --- src/backend/distributed/executor/multi_utility.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/backend/distributed/executor/multi_utility.c b/src/backend/distributed/executor/multi_utility.c index 2357e05fd..53ae650c7 100644 --- a/src/backend/distributed/executor/multi_utility.c +++ b/src/backend/distributed/executor/multi_utility.c @@ -326,10 +326,18 @@ multi_ProcessUtility10(PlannedStmt *pstmt, { if (IsA(parsetree, IndexStmt)) { - /* copy parse tree since we might scribble on it to fix the schema name */ - parsetree = copyObject(parsetree); + /* + * copy parse tree since we might scribble on it to fix the schema name + * FIXME: PostgreSQL 10 changes caching behavior and breaks this approach, + * so for that version we do assign back the modified tree. + */ + Node *parsetreeCopy = copyObject(parsetree); - ddlJobs = PlanIndexStmt((IndexStmt *) parsetree, queryString); + ddlJobs = PlanIndexStmt((IndexStmt *) parsetreeCopy, queryString); + +#if (PG_VERSION_NUM < 100000) + parsetree = parsetreeCopy; +#endif } if (IsA(parsetree, DropStmt))