Skip to content

Commit 2efcd50

Browse files
committed
Disallow calling anything but plain functions via the fastpath API.
Reject aggregates, window functions, and procedures. Aggregates failed anyway, though with a somewhat obscure error message. Window functions would hit an Assert or null-pointer dereference. Procedures seemed to work as long as you didn't try to do transaction control, but (a) transaction control is sort of the point of a procedure, and (b) it's not entirely clear that no bugs lurk in that path. Given the lack of testing of this area, it seems safest to be conservative in what we support. Also reject proretset functions, as the fastpath protocol can't support returning a set. Also remove an easily-triggered assertion that the given OID isn't 0; the subsequent lookups can handle that case themselves. Per report from Theodor-Arsenij Larionov-Trichkin. Back-patch to all supported branches. (The procedure angle only applies in v11+, of course.) Discussion: https://postgr.es/m/2039442.1615317309@sss.pgh.pa.us
1 parent ee4ba01 commit 2efcd50

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/backend/tcop/fastpath.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ fetch_fp_info(Oid func_id, struct fp_info *fip)
121121
HeapTuple func_htp;
122122
Form_pg_proc pp;
123123

124-
Assert(OidIsValid(func_id));
125124
Assert(fip != NULL);
126125

127126
/*
@@ -135,15 +134,20 @@ fetch_fp_info(Oid func_id, struct fp_info *fip)
135134
MemSet(fip, 0, sizeof(struct fp_info));
136135
fip->funcid = InvalidOid;
137136

138-
fmgr_info(func_id, &fip->flinfo);
139-
140137
func_htp = SearchSysCache1(PROCOID, ObjectIdGetDatum(func_id));
141138
if (!HeapTupleIsValid(func_htp))
142139
ereport(ERROR,
143140
(errcode(ERRCODE_UNDEFINED_FUNCTION),
144141
errmsg("function with OID %u does not exist", func_id)));
145142
pp = (Form_pg_proc) GETSTRUCT(func_htp);
146143

144+
/* reject pg_proc entries that are unsafe to call via fastpath */
145+
if (pp->prokind != PROKIND_FUNCTION || pp->proretset)
146+
ereport(ERROR,
147+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
148+
errmsg("cannot call function %s via fastpath interface",
149+
NameStr(pp->proname))));
150+
147151
/* watch out for catalog entries with more than FUNC_MAX_ARGS args */
148152
if (pp->pronargs > FUNC_MAX_ARGS)
149153
elog(ERROR, "function %s has more than %d arguments",
@@ -156,6 +160,8 @@ fetch_fp_info(Oid func_id, struct fp_info *fip)
156160

157161
ReleaseSysCache(func_htp);
158162

163+
fmgr_info(func_id, &fip->flinfo);
164+
159165
/*
160166
* This must be last!
161167
*/

0 commit comments

Comments
 (0)