8000 Add a stack overflow check to copyObject(). · patchsoft/postgres@0ae63a4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ae63a4

Browse files
committed
Add a stack overflow check to copyObject().
There are some code paths, such as SPI_execute(), where we invoke copyObject() on raw parse trees before doing parse analysis on them. Since the bison grammar is capable of building heavily nested parsetrees while itself using only minimal stack depth, this means that copyObject() can be the front-line function that hits stack overflow before anything else does. Accordingly, it had better have a check_stack_depth() call. I did a bit of performance testing and found that this slows down copyObject() by only a few percent, so the hit ought to be negligible in the context of complete processing of a query. Per off-list report from Toshihide Katayama. Back-patch to all supported branches.
1 parent 8a6eb2e commit 0ae63a4

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/backend/nodes/copyfuncs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "postgres.h"
2424

25+
#include "miscadmin.h"
2526
#include "nodes/parsenodes.h"
2627
#include "nodes/plannodes.h"
2728
#include "nodes/relation.h"
@@ -2684,6 +2685,9 @@ copyObject(void *from)
26842685
if (from == NULL)
26852686
return NULL;
26862687

2688+
/* Guard against stack overflow due to overly complex expressions */
2689+
check_stack_depth();
2690+
26872691
switch (nodeTag(from))
26882692
{
26892693
/*

0 commit comments

Comments
 (0)
0