pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15428: "Inception" with recursive prepared statement causes infinite loop
2+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2018-10-15 d48da369ab db9034bf76 ca361554c2 10412cef11 eb01ea2a36 3a60c8bb16 9d4212afa1  Check for stack overrun in standard_ProcessUtility().
* BUG #15428: "Inception" with recursive prepared statement causes infinite loop
@ 2018-10-12 09:00 PG Bug reporting form <noreply@postgresql.org>
  2018-10-15 16:21 ` Re: BUG #15428: "Inception" with recursive prepared statement causes infinite loop Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2018-10-12 09:00 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: mborch@gmail.com

The following bug has been logged on the website:

Bug reference:      15428
Logged by:          Malthe Borch
Email address:      mborch@gmail.com
PostgreSQL version: 11beta4
Operating system:   MacOS
Description:        

Using the extended query message flow, I prepare, bind and execute a query
as a named statement.

If I repeat this again with the query "execute <name>" – the backend crashes
with a segmentation fault due to an infinite recursion (see excerpt
below).

While it doesn't really make sense to prepare a statement that executes a
statement, there still seems to be a real issue here. It doesn't seem to
make a difference using the unnamed portal or a unique name per statement.

----

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS
(code=2, address=0x7ffeef3fffa8)
  * frame #0: 0x000000010073b49a postgres`dopr(target=<unavailable>,
format=<unavailable>, args=<unavailable>) at snprintf.c:377
    frame #1: 0x000000010073c84f postgres`pg_vsprintf(str="0\x04@??",
fmt="<unnamed portal %u>", args=0x00007ffeef4003c0) at snprintf.c:223
    frame #2: 0x000000010073ca0c postgres`pg_sprintf(str="0\x04@??",
fmt="<unnamed portal %u>") at snprintf.c:236
    frame #3: 0x000000010070d842 postgres`CreateNewPortal at
portalmem.c:244
    frame #4: 0x000000010025a3f2
postgres`ExecuteQuery(stmt=0x000000010200aa48,
intoClause=0x0000000000000000, queryString="execute test($1)",
params=0x0000000000000000, dest=0x000000010093da08, completionTag="") at
prepare.c:237
    frame #5: 0x0000000100512924
postgres`standard_ProcessUtility(pstmt=0x000000010200a9b0,
queryString="execute test($1)", context=PROCESS_UTILITY_QUERY,
params=0x0000000000000000, queryEnv=0x0000000000000000,
dest=0x000000010093da08, completionTag="") at utility.c:564
    frame #6: 0x00000001005123a5
postgres`ProcessUtility(pstmt=0x000000010200a9b0, queryString="execute
test($1)", context=PROCESS_UTILITY_QUERY, params=0x0000000000000000,
queryEnv=0x0000000000000000, dest=0x000000010093da08, completionTag="") at
utility.c:360
    frame #7: 0x0000000100511d87
postgres`PortalRunUtility(portal=0x000000010e912c88,
pstmt=0x000000010200a9b0, isTopLevel=<unavailable>,
setHoldSnapshot=<unavailable>, dest=<unavailable>, completionTag="") at
pquery.c:1178
    frame #8: 0x00000001005114e4
postgres`PortalRunMulti(portal=0x000000010e912c88, isTopLevel=false,
setHoldSnapshot=false, dest=0x000000010093da08, altdest=0x000000010093da08,
completionTag="") at pquery.c:0
    frame #9: 0x0000000100510d4e
postgres`PortalRun(portal=0x000000010e912c88, count=9223372036854775807,
isTopLevel=false, run_once=<unavailable>, dest=0x000000010093da08,
altdest=0x000000010093da08, completionTag="") at pquery.c:799
    frame #10: 0x000000010025a632
postgres`ExecuteQuery(stmt=0x000000010200aa48,
intoClause=0x0000000000000000, queryString="execute test($1)",
params=0x0000000000000000, dest=0x000000010093da08, completionTag="") at
prepare.c:304



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #15428: "Inception" with recursive prepared statement causes infinite loop
  2018-10-12 09:00 BUG #15428: "Inception" with recursive prepared statement causes infinite loop PG Bug reporting form <noreply@postgresql.org>
@ 2018-10-15 16:21 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2018-10-15 16:21 UTC (permalink / raw)
  To: mborch@gmail.com; +Cc: pgsql-bugs@lists.postgresql.org

> Using the extended query message flow, I prepare, bind and execute a query
> as a named statement.
> If I repeat this again with the query "execute <name>" – the backend crashes
> with a segmentation fault due to an infinite recursion (see excerpt
> below).

Hm, yeah.  I'm inclined to think that the right fix is a
check_stack_depth() call in standard_ProcessUtility.
That transforms the case into

$ ./test
PQexecPrepared failed: ERROR:  stack depth limit exceeded
HINT:  Increase the configuration parameter "max_stack_depth" (currently 2048kB), after ensuring the platform's stack depth limit is adequate.

which seems like an adequate response, and would cover some
related scenarios as well.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2018-10-15 16:21 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-10-12 09:00 BUG #15428: "Inception" with recursive prepared statement causes infinite loop PG Bug reporting form <noreply@postgresql.org>
2018-10-15 16:21 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox