Skip to content

Commit a55c32a

Browse files
committed
Run input function allowing soft errors only
When parsing WITH clause arguments for ALTER TABLE to extract compression parameters, syntax errors in the text format are caught using PG_TRY and PG_CATCH and then returning an indication if the parse succeeded or not. If an out of memory error occurs inside execution of the input function and this error is caught, it can continue executing and potentially cause cascading out of memory errors and in the end exhausing the error stack. This commit solves this by using `InputFunctionCallSafe` rather than catching the error, allowing soft errors like a syntax error to return with a failure but propagating hard errors like out-of-memory errors, allowing the backend to deal with it properly.
1 parent 23a1fd3 commit a55c32a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/with_clause_parser.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <access/htup_details.h>
1010
#include <catalog/pg_type.h>
1111
#include <commands/defrem.h>
12+
#include <nodes/miscnodes.h>
1213
#include <nodes/parsenodes.h>
1314
#include <utils/builtins.h>
1415
#include <utils/lsyscache.h>
@@ -140,6 +141,8 @@ parse_arg(WithClauseDefinition arg, DefElem *def)
140141
Datum val;
141142
Oid in_fn;
142143
Oid typIOParam;
144+
ErrorSaveContext escontext = { T_ErrorSaveContext };
145+
FmgrInfo flinfo;
143146

144147
if (!OidIsValid(arg.type_id))
145148
ereport(ERROR,
@@ -161,11 +164,9 @@ parse_arg(WithClauseDefinition arg, DefElem *def)
161164

162165
Assert(OidIsValid(in_fn));
163166

164-
PG_TRY();
165-
{
166-
val = OidInputFunctionCall(in_fn, value, typIOParam, -1);
167-
}
168-
PG_CATCH();
167+
fmgr_info(in_fn, &flinfo);
168+
169+
if (!InputFunctionCallSafe(&flinfo, value, typIOParam, -1, (Node *) &escontext, &val))
169170
{
170171
Form_pg_type typetup;
171172
HeapTuple tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(arg.type_id));
@@ -186,6 +187,6 @@ parse_arg(WithClauseDefinition arg, DefElem *def)
186187
def->defname,
187188
NameStr(typetup->typname))));
188189
}
189-
PG_END_TRY();
190+
190191
return val;
191192
}

0 commit comments

Comments
 (0)