]> 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:45 +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 85e2a902a2c5e11d2f2698157e4674f4a858870c..c8c8e4297c45ee55be220b59df9aad3e58484237 100644 (file)
@@ -75,6 +75,7 @@
 #include "commands/trigger.h"
 #include "commands/typecmds.h"
 #include "funcapi.h"
+#include "miscadmin.h"
 #include "nodes/nodeFuncs.h"
 #include "parser/parsetree.h"
 #include "rewrite/rewriteRemove.h"
@@ -516,6 +517,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 bd6b9c479ad965a0adedc1ba444da3662de10d6b..919790943cb8f89a263aeb7bc25299605c8931ec 100644 (file)
@@ -552,6 +552,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 5daa5605998721d7605e7e01fdfeaba02ab8f44f..8b27ab9739a45ddf20f9bc0ddf1bdf56fe1125de 100644 (file)
@@ -6745,6 +6745,9 @@ ATExecAddColumn(List **wqueue, AlteredTableInfo *tab, Relation rel,
        TupleDesc       tupdesc;
        FormData_pg_attribute *aattr[] = {&attribute};
 
+       /* 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((*cmd)->subtype, rel, ATT_TABLE | ATT_FOREIGN_TABLE);
@@ -8477,6 +8480,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();
 
@@ -10939,6 +10946,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;
@@ -11955,6 +11965,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(AT_DropConstraint, rel, ATT_TABLE | ATT_FOREIGN_TABLE);
index 3ef684a75d38195f41eb1c7e3cb2342cf902a40c..1b7aaf092cc2ab0f18e2c7c782f2bf001bb030e0 100644 (file)
@@ -2347,6 +2347,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 c8368eacb649b9b90da392058d140bb6d2aef0ee..f7edfb352e8cd6789732f55ba9d5d17a772fcb97 100644 (file)
@@ -1231,6 +1231,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");