Hi,

using sqlsmith I found a way to induce an AssertArg failure in src/backend/executor/functions.c:check_sql_fn_retval() for assert-enabled builds. It boils down to creating a function and calling it like this:

CREATE FUNCTION bad_argument_assert(anyarray, integer) RETURNS anyarray LANGUAGE sql AS $$select $1$$;
SELECT bad_argument_assert(CAST(NULL AS ANYARRAY), 0);

TRAP: BadArgument("!(!((rettype) == 2283 || (rettype) == 2277 || (rettype) == 2776 || (rettype) == 3500 || (rettype) == 3831))", File: "src/backend/executor/functions.c", Line: 1539)

Back-trace attached.

I've done a little bit of git-bisecting and this potential failure is there since at least February 2012.

The comment above the function definition specifically says that "we should never see a polymorphic pseudotype such as ANYELEMENT as rettype" but given that a non-assert-enabled build seems to cope with such pseudotypes well, I'm unsure the AssertArg is needed there at all.
#0  0x00007ffff7341a98 in __GI_raise (sig=sig@entry=6) at 
../sysdeps/unix/sysv/linux/raise.c:55
#1  0x00007ffff734369a in __GI_abort () at abort.c:89
#2  0x000000000094d594 in ExceptionalCondition (conditionName=0xb03c60 
"!(!((rettype) == 2283 || (rettype) == 2277 || (rettype) == 2776 || (rettype) 
== 3500 || (rettype) == 3831))", errorType=0xb03c51 "BadArgument", 
fileName=0xb03890 "src/backend/executor/functions.c", lineNumber=1539) at 
src/backend/utils/error/assert.c:54
#3  0x00000000006840c9 in check_sql_fn_retval (func_id=65539, rettype=2277, 
queryTreeList=0xf3b460, modifyTargetList=0x7fffffffc676 "", junkFilter=0x0) at 
src/backend/executor/functions.c:1539
#4  0x000000000075735c in inline_function (funcid=65539, result_type=2277, 
result_collid=0, input_collid=0, args=0xf09dd0, funcvariadic=0 '\000', 
func_tuple=0x7ffff7f99c30, context=0x7fffffffd960) at 
src/backend/optimizer/util/clauses.c:4706
#5  0x0000000000756508 in simplify_function (funcid=65539, result_type=2277, 
result_typmod=-1, result_collid=0, input_collid=0, args_p=0x7fffffffc838, 
funcvariadic=0 '\000', process_args=1 '\001', allow_non_const=1 '\001', 
context=0x7fffffffd960) at src/backend/optimizer/util/clauses.c:4187
#6  0x0000000000753f87 in eval_const_expressions_mutator (node=0xf09960, 
context=0x7fffffffd960) at src/backend/optimizer/util/clauses.c:2834
#7  0x00000000006cbb2f in expression_tree_mutator (node=0xf099b8, 
mutator=0x7539ac <eval_const_expressions_mutator>, context=0x7fffffffd960) at 
src/backend/nodes/nodeFuncs.c:2640
#8  0x0000000000755ead in eval_const_expressions_mutator (node=0xf099b8, 
context=0x7fffffffd960) at src/backend/optimizer/util/clauses.c:3806
#9  0x00000000006cbd2a in expression_tree_mutator (node=0xf09928, 
mutator=0x7539ac <eval_const_expressions_mutator>, context=0x7fffffffd960) at 
src/backend/nodes/nodeFuncs.c:2689
#10 0x0000000000755ead in eval_const_expressions_mutator (node=0xf09928, 
context=0x7fffffffd960) at src/backend/optimizer/util/clauses.c:3806
#11 0x0000000000753959 in eval_const_expressions (root=0xf09ae0, node=0xf09928) 
at src/backend/optimizer/util/clauses.c:2676
#12 0x00000000007365f7 in preprocess_expression (root=0xf09ae0, expr=0xf09928, 
kind=1) at src/backend/optimizer/plan/planner.c:831
#13 0x0000000000735f1c in subquery_planner (glob=0xf093a0, parse=0xf09048, 
parent_root=0x0, hasRecursion=0 '\000', tuple_fraction=0) at 
src/backend/optimizer/plan/planner.c:581
#14 0x0000000000735688 in standard_planner (parse=0xf09048, cursorOptions=256, 
boundParams=0x0) at src/backend/optimizer/plan/planner.c:307
#15 0x00000000007353ca in planner (parse=0xf09048, cursorOptions=256, 
boundParams=0x0) at src/backend/optimizer/plan/planner.c:177
#16 0x0000000000800d28 in pg_plan_query (querytree=0xf09048, cursorOptions=256, 
boundParams=0x0) at src/backend/tcop/postgres.c:798
#17 0x0000000000800ddb in pg_plan_queries (querytrees=0xf09aa8, 
cursorOptions=256, boundParams=0x0) at src/backend/tcop/postgres.c:857
#18 0x0000000000801080 in exec_simple_query (query_string=0xf07ee8 "select 
public.bad_argument_assert(CAST(NULL AS ANYARRAY), 0);") at 
src/backend/tcop/postgres.c:1022
#19 0x0000000000805342 in PostgresMain (argc=1, argv=0xe95e90, dbname=0xe95cf0 
"regression", username=0xe95cd0 "me") at src/backend/tcop/postgres.c:4059
#20 0x000000000077ed31 in BackendRun (port=0xeb6290) at 
src/backend/postmaster/postmaster.c:4258
#21 0x000000000077e495 in BackendStartup (port=0xeb6290) at 
src/backend/postmaster/postmaster.c:3932
#22 0x000000000077ac19 in ServerLoop () at 
src/backend/postmaster/postmaster.c:1690
#23 0x000000000077a24e in PostmasterMain (argc=3, argv=0xe94e10) at 
src/backend/postmaster/postmaster.c:1298
#24 0x00000000006c6216 in main (argc=3, argv=0xe94e10) at 
src/backend/main/main.c:228
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to