aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/prep/prepsecurity.c
diff options
context:
space:
mode:
authorDean Rasheed <dean.a.rasheed@gmail.com>2016-02-29 12:31:25 +0000
committerDean Rasheed <dean.a.rasheed@gmail.com>2016-02-29 12:31:25 +0000
commitf1dfcf63d9f076d9c200c0d7ee670899149e302a (patch)
treec0db8abfb1bac34736a3bc969a856d107af1275b /src/backend/optimizer/prep/prepsecurity.c
parent2d43c45e9d84d711a616d2fca7eb1b040ac5ddaf (diff)
downloadpostgresql-f1dfcf63d9f076d9c200c0d7ee670899149e302a.tar.gz
postgresql-f1dfcf63d9f076d9c200c0d7ee670899149e302a.zip
Fix incorrect varlevelsup in security_barrier_replace_vars().
When converting an RTE with securityQuals into a security barrier subquery RTE, ensure that the Vars in the new subquery's targetlist all have varlevelsup = 0 so that they correctly refer to the underlying base relation being wrapped. The original code was creating new Vars by copying them from existing Vars referencing the base relation found elsewhere in the query, but failed to account for the fact that such Vars could come from sublink subqueries, and hence have varlevelsup > 0. In practice it looks like this could only happen with nested security barrier views, where the outer view has a WHERE clause containing a correlated subquery, due to the order in which the Vars are processed. Bug: #13988 Reported-by: Adam Guthrie Backpatch-to: 9.4, where updatable SB views were introduced
Diffstat (limited to 'src/backend/optimizer/prep/prepsecurity.c')
-rw-r--r--src/backend/optimizer/prep/prepsecurity.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/backend/optimizer/prep/prepsecurity.c b/src/backend/optimizer/prep/prepsecurity.c
index ee1e1e40ef8..5167176f93c 100644
--- a/src/backend/optimizer/prep/prepsecurity.c
+++ b/src/backend/optimizer/prep/prepsecurity.c
@@ -446,6 +446,7 @@ security_barrier_replace_vars_walker(Node *node,
/* New variable for subquery targetlist */
newvar = copyObject(var);
newvar->varno = newvar->varnoold = 1;
+ newvar->varlevelsup = 0;
attno = list_length(context->targetlist) + 1;
tle = makeTargetEntry((Expr *) newvar,