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 00:53:07 +0000 (02:53 +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 46ced9bb60136872b65ee2f88e49c11ee1572d55..baccd290b1410beaeceee3b0e3b8ec15688b5c65 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"
@@ -509,6 +510,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 679851dc502bc55c0c88cd30452db54a0650927c..a98a511583799b83ac36cbabc510e69489240cc2 100644 (file)
@@ -595,6 +595,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 1432a567bcf703381ae248d042ccb2e4ca577ff2..4783b6c0631ec25373ad3719bdf37220cc35db3c 100644 (file)
@@ -5941,6 +5941,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);
@@ -7505,6 +7508,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();
 
@@ -9632,6 +9639,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;
@@ -10616,6 +10626,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 7bda315449a187dff178590779f9c2b36227e605..519dbd0dcbccc651b25feeb5b229e48e0c1839b9 100644 (file)
@@ -2458,6 +2458,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 37b08f1742a5270545fa17920108e0b2fa1f49c1..e115b03a3d3f8519f4a0251c49f278eca05c24f4 100644 (file)
@@ -1160,6 +1160,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");