postgres.git / summary / log / commit / refs

commit    ee6c8875a567c591a6602a40f4c064641806e4bc
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Tue Dec 07 03:56:02 2010 +0000
First released in: 9.1.0, 8.1.23, 8.2.19, 8.3.13, 8.4.6, 9.0.2

    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.


src/backend/nodes/copyfuncs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index b927f41e205..23425466464 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" @@ -3014,6 +3015,9 @@ copyObject(void *from) if (from == NULL) return NULL; + /* Guard against stack overflow due to overly complex expressions */ + check_stack_depth(); + switch (nodeTag(from)) { /* [parent: 0d45e8c56079]