Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4d225ba

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 bbcfee0 commit 4d225ba

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
@@ -198,7 +198,6 @@ fetch_fp_info(Oid func_id, struct fp_info *fip)
198198
HeapTuple func_htp;
199199
Form_pg_proc pp;
200200

201-
Assert(OidIsValid(func_id));
202201
Assert(fip != NULL);
203202

204203
/*
@@ -212,15 +211,20 @@ fetch_fp_info(Oid func_id, struct fp_info *fip)
212211
MemSet(fip, 0, sizeof(struct fp_info));
213212
fip->funcid = InvalidOid;
214213

215-
fmgr_info(func_id, &fip->flinfo);
216-
217214
func_htp = SearchSysCache1(PROCOID, ObjectIdGetDatum(func_id));
218215
if (!HeapTupleIsValid(func_htp))
219216
ereport(ERROR,
220217
(errcode(ERRCODE_UNDEFINED_FUNCTION),
221218
errmsg("function with OID %u does not exist", func_id)));
222219
pp = (Form_pg_proc) GETSTRUCT(func_htp);
223220

221+
/* reject pg_proc entries that are unsafe to call via fastpath */
222+
if (pp->prokind != PROKIND_FUNCTION || pp->proretset)
223+
ereport(ERROR,
224+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
225+
errmsg("cannot call function %s via fastpath interface",
226+
NameStr(pp->proname))));
227+
224228
/* watch out for catalog entries with more than FUNC_MAX_ARGS args */
225229
if (pp->pronargs > FUNC_MAX_ARGS)
226230
elog(ERROR, "function %s has more than %d arguments",
@@ -233,6 +237,8 @@ fetch_fp_info(Oid func_id, struct fp_info *fip)
233237

234238
ReleaseSysCache(func_htp);
235239

240+
fmgr_info(func_id, &fip->flinfo);
241+
236242
/*
237243
* This must be last!
238244
*/

0 commit comments

Comments
 (0)