Skip to content

Commit e60122b

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 9eaba23 commit e60122b

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"
@@ -2978,6 +2979,9 @@ equal(const void *a, const void *b)
29782979
if (nodeTag(a) != nodeTag(b))
29792980
return false;
29802981

2982+
/* Guard against stack overflow due to overly complex expressions */
2983+
check_stack_depth();
2984+
29812985
switch (nodeTag(a))
29822986
{
29832987
/*

src/backend/nodes/nodeFuncs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3701,6 +3701,9 @@ planstate_tree_walker(PlanState *planstate,
37013701
Plan *plan = planstate->plan;
37023702
ListCell *lc;
37033703

3704+
/* Guard against stack overflow due to overly complex plan trees */
3705+
check_stack_depth();
3706+
37043707
/* initPlan-s */
37053708
if (planstate_walk_subplans(planstate->initPlan, walker, context))
37063709
return true;

src/backend/nodes/outfuncs.c

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

3232
#include "lib/stringinfo.h"
33+
#include "miscadmin.h"
3334
#include "nodes/extensible.h"
3435
#include "nodes/plannodes.h"
3536
#include "nodes/relation.h"
@@ -3615,6 +3616,9 @@ _outPartitionRangeDatum(StringInfo str, const PartitionRangeDatum *node)
36153616
void
36163617
outNode(StringInfo str, const void *obj)
36173618
{
3619+
/* Guard against stack overflow due to overly complex expressions */
3620+
check_stack_depth();
3621+
36183622
if (obj == NULL)
36193623
appendStringInfoString(str, "<>");
36203624
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"
@@ -2452,6 +2453,9 @@ parseNodeString(void)
24522453

24532454
READ_TEMP_LOCALS();
24542455

2456+
/* Guard against stack overflow due to overly complex expressions */
2457+
check_stack_depth();
2458+
24552459
token = pg_strtok(&length);
24562460

24572461
#define MATCH(tokname, namelen) \

0 commit comments

Comments
 (0)