Skip to content

Commit 3af726a

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 3a691f8 commit 3af726a

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-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/relation.h"
3334
#include "utils/datum.h"
3435

@@ -2514,6 +2515,9 @@ equal(const void *a, const void *b)
25142515
if (nodeTag(a) != nodeTag(b))
25152516
return false;
25162517

2518+
/* Guard against stack overflow due to overly complex expressions */
2519+
check_stack_depth();
2520+
25172521
switch (nodeTag(a))
25182522
{
25192523
/*

src/backend/nodes/outfuncs.c

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

2626
#include "lib/stringinfo.h"
27+
#include "miscadmin.h"
2728
#include "nodes/plannodes.h"
2829
#include "nodes/relation.h"
2930
#include "utils/datum.h"
@@ -2757,6 +2758,9 @@ _outConstraint(StringInfo str, const Constraint *node)
27572758
static void
27582759
_outNode(StringInfo str, const void *obj)
27592760
{
2761+
/* Guard against stack overflow due to overly complex expressions */
2762+
check_stack_depth();
2763+
27602764
if (obj == NULL)
27612765
appendStringInfoString(str, "<>");
27622766
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
@@ -28,6 +28,7 @@
2828

2929
#include <math.h>
3030

31+
#include "miscadmin.h"
3132
#include "nodes/parsenodes.h"
3233
#include "nodes/readfuncs.h"
3334

@@ -1292,6 +1293,9 @@ parseNodeString(void)
12921293

12931294
READ_TEMP_LOCALS();
12941295

1296+
/* Guard against stack overflow due to overly complex expressions */
1297+
check_stack_depth();
1298+
12951299
token = pg_strtok(&length);
12961300

12971301
#define MATCH(tokname, namelen) \

0 commit comments

Comments
 (0)