aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/array_userfuncs.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2016-12-09 12:42:17 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2016-12-09 12:42:17 -0300
commit79c89f1f4e939b7a3f3bb4a76476dcda651cd58b (patch)
tree75bd72b6b8d0ff708f46b55a4988cb1ca696d48c /src/backend/utils/adt/array_userfuncs.c
parent86c6aaff6ead3e00a89fd0743195678bbc69790c (diff)
downloadpostgresql-79c89f1f4e939b7a3f3bb4a76476dcda651cd58b.tar.gz
postgresql-79c89f1f4e939b7a3f3bb4a76476dcda651cd58b.zip
Fix crasher bug in array_position(s)
array_position and its cousin array_positions were caching the element type equality function's FmgrInfo without being careful enough to put it in a long-lived context. This is obviously broken but it didn't matter in most cases; only when using arrays of records (involving record_eq) it becomes a problem. The fix is to ensure that the type's equality function's FmgrInfo is cached in the array_position's flinfo->fn_mcxt rather than the current memory context. Apart from record types, the only other case that seems complex enough to possibly cause the same problem are range types. I didn't find a way to reproduce the problem with those, so I only include the test case submitted with the bug report as regression test. Bug report and patch: Junseok Yang Discussion: https://postgr.es/m/CAE+byMupUURYiZ6bKYgMZb9pgV1CYAijJGqWj-90W=nS7uEOeA@mail.gmail.com Backpatch to 9.5, where array_position appeared.
Diffstat (limited to 'src/backend/utils/adt/array_userfuncs.c')
-rw-r--r--src/backend/utils/adt/array_userfuncs.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/backend/utils/adt/array_userfuncs.c b/src/backend/utils/adt/array_userfuncs.c
index 8d6fa41a3c5..9eb678add44 100644
--- a/src/backend/utils/adt/array_userfuncs.c
+++ b/src/backend/utils/adt/array_userfuncs.c
@@ -795,7 +795,8 @@ array_position_common(FunctionCallInfo fcinfo)
format_type_be(element_type))));
my_extra->element_type = element_type;
- fmgr_info(typentry->eq_opr_finfo.fn_oid, &my_extra->proc);
+ fmgr_info_cxt(typentry->eq_opr_finfo.fn_oid, &my_extra->proc,
+ fcinfo->flinfo->fn_mcxt);
}
/* Examine each array element until we find a match. */
@@ -933,7 +934,8 @@ array_positions(PG_FUNCTION_ARGS)
format_type_be(element_type))));
my_extra->element_type = element_type;
- fmgr_info(typentry->eq_opr_finfo.fn_oid, &my_extra->proc);
+ fmgr_info_cxt(typentry->eq_opr_finfo.fn_oid, &my_extra->proc,
+ fcinfo->flinfo->fn_mcxt);
}
/*