segfault in HEAD when too many nested functions call

From: Julien Rouhaud <julien(dot)rouhaud(at)dalibo(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Cc: Andres Freund <andres(at)anarazel(dot)de>
Subject: segfault in HEAD when too many nested functions call
Date: 2017-07-15 02:07:03
Message-ID: b0af9eaa-130c-60d0-9e4e-7a135b1e0c76@dalibo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello,

Since b8d7f053c5c2bf2a7e8734fe3327f6a8bc711755 (Andres in Cc), if you
write queries which result in infinite recursion (or just too many
nested function calls), execution ends with segfault instead of intended
exhausted max_stack_depth:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000df851e in DirectFunctionCall1Coll (
func=<error reading variable: Cannot access memory at address
0x7ffef5972f98>,
collation=<error reading variable: Cannot access memory at address
0x7ffef5972f94>,
arg1=<error reading variable: Cannot access memory at address
0x7ffef5972f88>) at fmgr.c:708

Please find attached a trivial patch to fix this. I'm not sure
ExecMakeTableFunctionResult() is the best or only place that needs to
check the stack depth.

I also attached a simple sql file to reproduce the issue if needed.
Should I add a regression test based on it?

--
Julien Rouhaud
http://dalibo.com - http://dalibo.org

Attachment Content-Type Size
segfault.sql application/sql 363 bytes
fix_segfault_recursion.diff text/x-patch 505 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2017-07-15 02:14:43 Re: Pluggable storage
Previous Message Peter Geoghegan 2017-07-15 00:06:16 Re: [WIP] Zipfian distribution in pgbench