-- Regression for a backend crash: pljs.find_function() on a function the -- caller lacks EXECUTE permission on used to `return` from *inside* a PG_TRY -- block. That left PG_exception_stack pointing at a dead stack frame, so the -- next ereport(ERROR) siglongjmp()'d into freed memory and the whole backend -- segfaulted (signal 11). This test drives that exact sequence and must -- complete with a clean error instead of crashing. CREATE FUNCTION ff_secret() RETURNS int LANGUAGE sql AS 'SELECT 42'; REVOKE ALL ON FUNCTION ff_secret() FROM PUBLIC; -- Roles are cluster-wide, and this test is built to kill the backend when the -- fix is absent -- which skips the DROP ROLE at the bottom and leaves the role -- behind. Drop it up front so the next run is not blocked by the last one. -- The notice is silenced so the output does not depend on whether it was there. SET client_min_messages = warning; DROP ROLE IF EXISTS ff_limited; RESET client_min_messages; CREATE ROLE ff_limited; -- Call find_function on a function we lack EXECUTE on (the permission-denied -- path), then force an *unwrapped* elog(ERROR) via an int[] return of a -- non-array value. Pre-fix this crashed the backend. CREATE FUNCTION ff_probe() RETURNS int[] LANGUAGE pljs AS $$ try { pljs.find_function('ff_secret()'); } catch (e) { } return 5; $$; GRANT EXECUTE ON FUNCTION ff_probe() TO ff_limited; SET ROLE ff_limited; -- Expect a clean "value is not an Array" error, NOT a crash. SELECT ff_probe(); RESET ROLE; -- The backend is still alive and usable. SELECT 1 AS alive; -- The permission-denied fall-through path on its own (find_function returns -- undefined) followed by more work must also not crash. SET ROLE ff_limited; DO $$ pljs.find_function('ff_secret()'); pljs.elog(NOTICE, 'survived'); $$ LANGUAGE pljs; RESET ROLE; SELECT 1 AS still_alive; DROP FUNCTION ff_probe(); DROP FUNCTION ff_secret(); DROP ROLE ff_limited;