]> git.ipfire.org Git - thirdparty/postgresql.git/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/outfuncs.c
src/backend/nodes/readfuncs.c

index 9a50523d476eddc782ea49761dd59a605528f282..e32b96eb1e24f9fd85fb0d566906f86e9953c539 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "postgres.h"
 
+#include "miscadmin.h"
 #include "nodes/relation.h"
 #include "utils/datum.h"
 
@@ -2676,6 +2677,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 5c03e9f2aa8431ab9ec0450f69cd95ff5716e8d6..8d9280197bb5cf2c939b648b4c31cbcc369f451d 100644 (file)
@@ -24,6 +24,7 @@
 #include <ctype.h>
 
 #include "lib/stringinfo.h"
+#include "miscadmin.h"
 #include "nodes/plannodes.h"
 #include "nodes/relation.h"
 #include "utils/datum.h"
@@ -2941,6 +2942,9 @@ _outConstraint(StringInfo str, const Constraint *node)
 static 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 32b23fff097ca576e20f928ed8da3b2b6437600a..a285af302f8c93424ee0896a266265452e9b842f 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <math.h>
 
+#include "miscadmin.h"
 #include "nodes/parsenodes.h"
 #include "nodes/readfuncs.h"
 
@@ -1382,6 +1383,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) \