summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2010-12-07 03:55:56 +0000
committerTom Lane2010-12-07 03:55:56 +0000
commit234ad01f9ea08514b1368bbf214e6c779e372a1a (patch)
tree59e78215baee7d0b9cb4059b7081fb162ece5c07
parent6bd3753d4d66bd78ac6d3b694910914f81212d56 (diff)
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.
-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 91b1e0d826a..4f095fd3083 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"
@@ -3438,6 +3439,9 @@ copyObject(void *from)
if (from == NULL)
return NULL;
+ /* Guard against stack overflow due to overly complex expressions */
+ check_stack_depth();
+
switch (nodeTag(from))
{
/*