Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ae5e3b

Browse files
committed
Check that aggregate creator has the right to execute the transition
functions of the aggregate, at both aggregate creation and execution times.
1 parent f76730e commit 5ae5e3b

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/backend/catalog/pg_aggregate.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.69 2004/12/31 21:59:38 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_aggregate.c,v 1.70 2005/01/27 23:42:15 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -22,10 +22,13 @@
2222
#include "catalog/pg_aggregate.h"
2323
#include "catalog/pg_language.h"
2424
#include "catalog/pg_proc.h"
25+
#include "miscadmin.h"
2526
#include "optimizer/cost.h"
2627
#include "parser/parse_coerce.h"
2728
#include "parser/parse_func.h"
29+
#include "utils/acl.h"
2830
#include "utils/builtins.h"
31+
#include "utils/lsyscache.h"
2932
#include "utils/syscache.h"
3033

3134

@@ -262,6 +265,7 @@ lookup_agg_function(List *fnName,
262265
bool retset;
263266
Oid *true_oid_array;
264267
FuncDetailCode fdresult;
268+
AclResult aclresult;
265269

266270
/*
267271
* func_get_detail looks up the function in the catalogs, does
@@ -326,5 +330,10 @@ lookup_agg_function(List *fnName,
326330
errmsg("function %s requires run-time type coercion",
327331
func_signature_string(fnName, nargs, true_oid_array))));
328332

333+
/* Check aggregate creator has permission to call the function */
334+
aclresult = pg_proc_aclcheck(fnOid, GetUserId(), ACL_EXECUTE);
335+
if (aclresult != ACLCHECK_OK)
336+
aclcheck_error(aclresult, ACL_KIND_PROC, get_func_name(fnOid));
337+
329338
return fnOid;
330339
}

src/backend/executor/nodeAgg.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* Portions Copyright (c) 1994, Regents of the University of California
4646
*
4747
* IDENTIFICATION
48-
* $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.126 2004/12/31 21:59:45 pgsql Exp $
48+
* $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.127 2005/01/27 23:42:18 tgl Exp $
4949
*
5050
*-------------------------------------------------------------------------
5151
*/
@@ -55,6 +55,7 @@
5555
#include "access/heapam.h"
5656
#include "catalog/pg_aggregate.h"
5757
#include "catalog/pg_operator.h"
58+
#include "catalog/pg_proc.h"
5859
#include "executor/executor.h"
5960
#include "executor/nodeAgg.h"
6061
#include "miscadmin.h"
@@ -1260,6 +1261,35 @@ ExecInitAgg(Agg *node, EState *estate)
12601261
peraggstate->transfn_oid = transfn_oid = aggform->aggtransfn;
12611262
peraggstate->finalfn_oid = finalfn_oid = aggform->aggfinalfn;
12621263

1264+
/* Check that aggregate owner has permission to call component fns */
1265+
{
1266+
HeapTuple procTuple;
1267+
AclId aggOwner;
1268+
1269+
procTuple = SearchSysCache(PROCOID,
1270+
ObjectIdGetDatum(aggref->aggfnoid),
1271+
0, 0, 0);
1272+
if (!HeapTupleIsValid(procTuple))
1273+
elog(ERROR, "cache lookup failed for function %u",
1274+
aggref->aggfnoid);
1275+
aggOwner = ((Form_pg_proc) GETSTRUCT(procTuple))->proowner;
1276+
ReleaseSysCache(procTuple);
1277+
1278+
aclresult = pg_proc_aclcheck(transfn_oid, aggOwner,
1279+
ACL_EXECUTE);
1280+
if (aclresult != ACLCHECK_OK)
1281+
aclcheck_error(aclresult, ACL_KIND_PROC,
1282+
get_func_name(transfn_oid));
1283+
if (OidIsValid(finalfn_oid))
1284+
{
1285+
aclresult = pg_proc_aclcheck(finalfn_oid, aggOwner,
1286+
ACL_EXECUTE);
1287+
if (aclresult != ACLCHECK_OK)
1288+
aclcheck_error(aclresult, ACL_KIND_PROC,
1289+
get_func_name(finalfn_oid));
1290+
}
1291+
}
1292+
12631293
/* resolve actual type of transition state, if polymorphic */
12641294
aggtranstype = aggform->aggtranstype;
12651295
if (aggtranstype == ANYARRAYOID || aggtranstype == ANYELEMENTOID)

0 commit comments

Comments
 (0)