]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Backpatch missing check_stack_depth() to some recursive functions
authorAlexander Korotkov <akorotkov@postgresql.org>
Fri, 16 Feb 2024 14:02:00 +0000 (16:02 +0200)
committerAlexander Korotkov <akorotkov@postgresql.org>
Mon, 11 Mar 2024 01:06:10 +0000 (03:06 +0200)
Backpatch changes from d57b7cc33375bcba6cbd to all supported branches per
proposal of Egor Chindyaskin.

Discussion: https://postgr.es/m/DE5FD776-A8CD-4378-BCFA-3BF30F1F6D60%40mail.ru

src/backend/catalog/dependency.c
src/backend/catalog/heap.c
src/backend/commands/tablecmds.c
src/backend/optimizer/util/clauses.c
src/backend/utils/adt/jsonpath_exec.c

index 11bc277ba32cbd01314e0dd4be581f2235e6c1a6..3d67525c7e021c848273031549f46af44dedc9a6 100644 (file)
@@ -73,6 +73,7 @@
 #include "commands/sequence.h"
 #include "commands/trigger.h"
 #include "commands/typecmds.h"
+#include "miscadmin.h"
 #include "nodes/nodeFuncs.h"
 #include "parser/parsetree.h"
 #include "rewrite/rewriteRemove.h"
@@ -510,6 +511,12 @@ findDependentObjects(const ObjectAddress *object,
        if (stack_address_present_add_flags(object, objflags, stack))
                return;
 
+       /*
+        * since this function recurses, it could be driven to stack overflow,
+        * because of the deep dependency tree, not only due to dependency loops.
+        */
+       check_stack_depth();
+
        /*
         * It's also possible that the target object has already been completely
         * processed and put into targetObjects.  If so, again we just add the
index 89a97831ec73e74c3e4e001ef600ec6cbf9c03dc..6628ac1009b30da3d27fd7621d64f0c4ab368875 100644 (file)
@@ -593,6 +593,9 @@ CheckAttributeType(const char *attname,
        char            att_typtype = get_typtype(atttypid);
        Oid                     att_typelem;
 
+       /* since this function recurses, it could be driven to stack overflow */
+       check_stack_depth();
+
        if (att_typtype == TYPTYPE_PSEUDO)
        {
                /*
index 12b46b921a289b3537971108f6b0ff51c94d77f4..b24bc465d31be00c25d9ef196e90724bd2e0c169 100644 (file)
@@ -6231,6 +6231,9 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
        AclResult       aclresult;
        ObjectAddress address;
 
+       /* since this function recurses, it could be driven to stack overflow */
+       check_stack_depth();
+
        /* At top level, permission check was done in ATPrepCmd, else do it */
        if (recursing)
                ATSimplePermissions(rel, ATT_TABLE | ATT_FOREIGN_TABLE);
@@ -7956,6 +7959,10 @@ ATExecDropColumn(List **wqueue, Relation rel, const char *colName,
 
        /* Initialize addrs on the first invocation */
        Assert(!recursing || addrs != NULL);
+
+       /* since this function recurses, it could be driven to stack overflow */
+       check_stack_depth();
+
        if (!recursing)
                addrs = new_object_addresses();
 
@@ -10086,6 +10093,9 @@ ATExecAlterConstrRecurse(Constraint *cmdcon, Relation conrel, Relation tgrel,
        Oid                     refrelid;
        bool            changed = false;
 
+       /* since this function recurses, it could be driven to stack overflow */
+       check_stack_depth();
+
        currcon = (Form_pg_constraint) GETSTRUCT(contuple);
        conoid = currcon->oid;
        refrelid = currcon->confrelid;
@@ -11067,6 +11077,9 @@ ATExecDropConstraint(Relation rel, const char *constrName,
        bool            is_no_inherit_constraint = false;
        char            contype;
 
+       /* since this function recurses, it could be driven to stack overflow */
+       check_stack_depth();
+
        /* At top level, permission check was done in ATPrepCmd, else do it */
        if (recursing)
                ATSimplePermissions(rel, ATT_TABLE | ATT_FOREIGN_TABLE);
index 4030f17d737d5aaca8766ac2c5e990dfa5106720..4ad66b9594de7ab85814a3ad5af2467244094632 100644 (file)
@@ -2456,6 +2456,10 @@ static Node *
 eval_const_expressions_mutator(Node *node,
                                                           eval_const_expressions_context *context)
 {
+
+       /* since this function recurses, it could be driven to stack overflow */
+       check_stack_depth();
+
        if (node == NULL)
                return NULL;
        switch (nodeTag(node))
index bbb3125c1d19c2faed5793408a3e4e4136ca2983..ee97a62d105f0fb55720807b3b9a59fa40c1aad6 100644 (file)
@@ -1235,6 +1235,9 @@ executeBoolItem(JsonPathExecContext *cxt, JsonPathItem *jsp,
        JsonPathBool res;
        JsonPathBool res2;
 
+       /* since this function recurses, it could be driven to stack overflow */
+       check_stack_depth();
+
        if (!canHaveNext && jspHasNext(jsp))
                elog(ERROR, "boolean jsonpath item cannot have next item");