]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add stack depth check to QueueFKConstraintValidation().
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 26 May 2026 15:58:25 +0000 (11:58 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 26 May 2026 15:58:25 +0000 (11:58 -0400)
QueueFKConstraintValidation() recurses through the partition hierarchy
to queue child constraint validations and to mark child rows as
validated.  With a sufficiently deep partition tree, this can result
in a stack-overflow crash.  Defend against that as we do elsewhere.

Bug: #19482
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19482-4cc37cbf52d55235@postgresql.org
Backpatch-through: 18

src/backend/commands/tablecmds.c

index 1e0bacf85fc87b46caec0c1ee3568e876ebe1d9d..a1845240a98c457389024e74c00a8186e06be61f 100644 (file)
@@ -13281,6 +13281,9 @@ QueueFKConstraintValidation(List **wqueue, Relation conrel, Relation fkrel,
        HeapTuple       copyTuple;
        Form_pg_constraint copy_con;
 
+       /* since this function recurses, it could be driven to stack overflow */
+       check_stack_depth();
+
        con = (Form_pg_constraint) GETSTRUCT(contuple);
        Assert(con->contype == CONSTRAINT_FOREIGN);
        Assert(!con->convalidated);