aboutsummaryrefslogtreecommitdiff
path: root/src/backend/nodes/copyfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-12-06 22:56:07 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2010-12-06 22:56:07 -0500
commit5271c3cd801cee7e571e9300b96108d7c11b9158 (patch)
treecff1d16fb1419b532c2ff804fb8161e9270f0317 /src/backend/nodes/copyfuncs.c
parentb0e2092319102c9a749ef4afd5efbdc37fb31b83 (diff)
downloadpostgresql-5271c3cd801cee7e571e9300b96108d7c11b9158.tar.gz
postgresql-5271c3cd801cee7e571e9300b96108d7c11b9158.zip
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.
Diffstat (limited to 'src/backend/nodes/copyfuncs.c')
-rw-r--r--src/backend/nodes/copyfuncs.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index 6aa7e559087..2c7e7a584fc 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -22,6 +22,7 @@
#include "postgres.h"
+#include "miscadmin.h"
#include "nodes/plannodes.h"
#include "nodes/relation.h"
#include "utils/datum.h"
@@ -2794,6 +2795,9 @@ copyObject(void *from)
if (from == NULL)
return NULL;
+ /* Guard against stack overflow due to overly complex expressions */
+ check_stack_depth();
+
switch (nodeTag(from))
{
/*