| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | statatt_build_stavalues->LOCAL_FCINFO wrong number |
| Date: | 2026-06-27 05:25:39 |
| Message-ID: | CACJufxEGah9PaiTQ=cG14GMMBsUQ3ohGct9tdSwbMQPQ0-nbbQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi.
https://git.postgresql.org/cgit/postgresql.git/commit/?id=213a1b89527049cb27bbcd6871fdb0c0916b43e1
+Datum
+statatt_build_stavalues(const char *staname, FmgrInfo *array_in,
Datum d, Oid typid,
+ int32 typmod, bool *ok)
+{
+ LOCAL_FCINFO(fcinfo, 8);
+ char *s;
+ Datum result;
+ ErrorSaveContext escontext = {T_ErrorSaveContext};
+
+ escontext.details_wanted = true;
+
+ s = TextDatumGetCString(d);
+
+ InitFunctionCallInfoData(*fcinfo, array_in, 3, InvalidOid,
+ (Node *) &escontext, NULL);
+
+ fcinfo->args[0].value = CStringGetDatum(s);
+ fcinfo->args[0].isnull = false;
+ fcinfo->args[1].value = ObjectIdGetDatum(typid);
+ fcinfo->args[1].isnull = false;
+ fcinfo->args[2].value = Int32GetDatum(typmod);
+ fcinfo->args[2].isnull = false;
+
+ result = FunctionCallInvoke(fcinfo);
+
+ pfree(s);
+
+ if (escontext.error_occurred)
+ {
+ escontext.error_data->elevel = WARNING;
+ ThrowErrorData(escontext.error_data);
+ *ok = false;
+ return (Datum) 0;
+ }
The above LOCAL_FCINFO(fcinfo, 8);
should be
LOCAL_FCINFO(fcinfo, 3);
That mistake is harmless now, but if somebody use
LOCAL_FCINFO(fcinfo, 1), then it may have potential problems.
So let's try to use InputFunctionCallSafe instead, see attached.
I found this while trying to use InputFunctionCallSafe inside array_in_safe.
Should we consider fully refactoring array_in_safe to use it too?
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-use-InputFunctionCallSafe-when-possible.patch | text/x-patch | 1.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Florents Tselai | 2026-06-27 05:40:51 | Re: More jsonpath methods: translate, split, join |
| Previous Message | ZizhuanLiu X-MAN | 2026-06-27 02:46:18 | Re: Reject ADD CONSTRAINT NOT NULL if name mismatches existing domain not-null constraint |