Skip to content

Commit 58538a0

Browse files
committed
Cause '*' and 'foo.*' notations to mark the referenced RTE(s) as
requiring read permissions. Up till now there was no possible case in which the RTEs wouldn't already have ACL_SELECT set ... but now that you can say something like 'INSERT INTO foo ... RETURNING *' this is an essential step. With this commit, a RETURNING clause adds the requirement for SELECT permissions on the target table if and only if the clause actually reads the value of at least one target-table column.
1 parent 65b2f93 commit 58538a0

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/backend/parser/parse_clause.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.156 2006/08/12 20:05:55 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_clause.c,v 1.157 2006/08/14 23:39:32 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -173,8 +173,9 @@ setTargetTable(ParseState *pstate, RangeVar *relation,
173173
* permissions.
174174
*
175175
* If we find an explicit reference to the rel later during parse
176-
* analysis, scanRTEForColumn will add the ACL_SELECT bit back again. That
177-
* can't happen for INSERT but it is possible for UPDATE and DELETE.
176+
* analysis, we will add the ACL_SELECT bit back again; see
177+
* scanRTEForColumn (for simple field references), ExpandColumnRefStar
178+
* (for foo.*) and ExpandAllTables (for *).
178179
*/
179180
rte->requiredPerms = requiredPerms;
180181

src/backend/parser/parse_target.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.147 2006/08/02 01:59:47 joe Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_target.c,v 1.148 2006/08/14 23:39:32 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -889,6 +889,9 @@ ExpandColumnRefStar(ParseState *pstate, ColumnRef *cref,
889889
rte = addImplicitRTE(pstate, makeRangeVar(schemaname, relname),
890890
cref->location);
891891

892+
/* Require read access --- see comments in setTargetTable() */
893+
rte->requiredPerms |= ACL_SELECT;
894+
892895
rtindex = RTERangeTablePosn(pstate, rte, &sublevels_up);
893896

894897
if (targetlist)
@@ -930,6 +933,9 @@ ExpandAllTables(ParseState *pstate)
930933
RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
931934
int rtindex = RTERangeTablePosn(pstate, rte, NULL);
932935

936+
/* Require read access --- see comments in setTargetTable() */
937+
rte->requiredPerms |= ACL_SELECT;
938+
933939
target = list_concat(target,
934940
expandRelAttrs(pstate, rte, rtindex, 0));
935941
}

0 commit comments

Comments
 (0)