]> granicus.if.org Git - postgresql/commitdiff
Add stack depth checks to key recursive functions in backend/nodes/*.c.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 10 Dec 2018 16:12:43 +0000 (11:12 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 10 Dec 2018 16:12:43 +0000 (11:12 -0500)
Although copyfuncs.c has a check_stack_depth call in its recursion,
equalfuncs.c, outfuncs.c, and readfuncs.c lacked one.  This seems
unwise.

Likewise fix planstate_tree_walker(), in branches where that exists.

Discussion: https://postgr.es/m/30253.1544286631@sss.pgh.pa.us

src/backend/nodes/equalfuncs.c
src/backend/nodes/nodeFuncs.c
src/backend/nodes/outfuncs.c
src/backend/nodes/readfuncs.c

index 2435b26f52f73180ea0be0d3a2d0fcf13fba4d5d..88ed8168081a921f438191263e2730ec6dc76277 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "postgres.h"
 
+#include "miscadmin.h"
 #include "nodes/extensible.h"
 #include "nodes/relation.h"
 #include "utils/datum.h"
@@ -3001,6 +3002,9 @@ equal(const void *a, const void *b)
        if (nodeTag(a) != nodeTag(b))
                return false;
 
+       /* Guard against stack overflow due to overly complex expressions */
+       check_stack_depth();
+
        switch (nodeTag(a))
        {
                        /*
index a10014f755b82665f9f9432f434f14f1f4ed1065..54b3dcff3ec3c91a112710efd3117314752039d5 100644 (file)
@@ -3726,6 +3726,9 @@ planstate_tree_walker(PlanState *planstate,
        Plan       *plan = planstate->plan;
        ListCell   *lc;
 
+       /* Guard against stack overflow due to overly complex plan trees */
+       check_stack_depth();
+
        /* initPlan-s */
        if (planstate_walk_subplans(planstate->initPlan, walker, context))
                return true;
index 6c3dad9ab3e852757829d8e41e6e8a75739f0875..96c6123545c853ee5040e3ab986c12ece78ef558 100644 (file)
@@ -30,6 +30,7 @@
 #include <ctype.h>
 
 #include "lib/stringinfo.h"
+#include "miscadmin.h"
 #include "nodes/extensible.h"
 #include "nodes/plannodes.h"
 #include "nodes/relation.h"
@@ -3703,6 +3704,9 @@ _outPartitionRangeDatum(StringInfo str, const PartitionRangeDatum *node)
 void
 outNode(StringInfo str, const void *obj)
 {
+       /* Guard against stack overflow due to overly complex expressions */
+       check_stack_depth();
+
        if (obj == NULL)
                appendStringInfoString(str, "<>");
        else if (IsA(obj, List) ||IsA(obj, IntList) || IsA(obj, OidList))
index 4362b00a425a7c2dfa167088e5f24a68f4b94c48..2ceb1e2ac239273aefb6706ed628fd7ace0c12da 100644 (file)
@@ -29,6 +29,7 @@
 #include <math.h>
 
 #include "fmgr.h"
+#include "miscadmin.h"
 #include "nodes/extensible.h"
 #include "nodes/parsenodes.h"
 #include "nodes/plannodes.h"
@@ -2539,6 +2540,9 @@ parseNodeString(void)
 
        READ_TEMP_LOCALS();
 
+       /* Guard against stack overflow due to overly complex expressions */
+       check_stack_depth();
+
        token = pg_strtok(&length);
 
 #define MATCH(tokname, namelen) \