Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0f9fd74

Browse files
committed
Add stack depth checks to key recursive functions in backend/nodes/*.c.
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
1 parent 078303f commit 0f9fd74

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

src/backend/nodes/equalfuncs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include "postgres.h"
3131

32+
#include "miscadmin.h"
3233
#include "nodes/extensible.h"
3334
#include "nodes/relation.h"
3435
#include "utils/datum.h"
@@ -2732,6 +2733,9 @@ equal(const void *a, const void *b)
27322733
if (nodeTag(a) != nodeTag(b))
27332734
return false;
27342735

2736+
/* Guard against stack overflow due to overly complex expressions */
2737+
check_stack_depth();
2738+
27352739
switch (nodeTag(a))
27362740
{
27372741
/*

src/backend/nodes/nodeFuncs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,6 +3623,9 @@ planstate_tree_walker(PlanState *planstate,
36233623
Plan *plan = planstate->plan;
36243624
ListCell *lc;
36253625

3626+
/* Guard against stack overflow due to overly complex plan trees */
3627+
check_stack_depth();
3628+
36263629
/* initPlan-s */
36273630
if (planstate_walk_subplans(planstate->initPlan, walker, context))
36283631
return true;

src/backend/nodes/outfuncs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <ctype.h>
2727

2828
#include "lib/stringinfo.h"
29+
#include "miscadmin.h"
2930
#include "nodes/extensible.h"
3031
#include "nodes/plannodes.h"
3132
#include "nodes/relation.h"
@@ -3276,6 +3277,9 @@ _outForeignKeyCacheInfo(StringInfo str, const ForeignKeyCacheInfo *node)
32763277
void
32773278
outNode(StringInfo str, const void *obj)
32783279
{
3280+
/* Guard against stack overflow due to overly complex expressions */
3281+
check_stack_depth();
3282+
32793283
if (obj == NULL)
32803284
appendStringInfoString(str, "<>");
32813285
else if (IsA(obj, List) ||IsA(obj, IntList) || IsA(obj, OidList))

src/backend/nodes/readfuncs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <math.h>
3030

3131
#include "fmgr.h"
32+
#include "miscadmin.h"
3233
#include "nodes/extensible.h"
3334
#include "nodes/parsenodes.h"
3435
#include "nodes/plannodes.h"
@@ -2262,6 +2263,9 @@ parseNodeString(void)
22622263

22632264
READ_TEMP_LOCALS();
22642265

2266+
/* Guard against stack overflow due to overly complex expressions */
2267+
check_stack_depth();
2268+
22652269
token = pg_strtok(&length);
22662270

22672271
#define MATCH(tokname, namelen) \

0 commit comments

Comments
 (0)