8000 Prevent stack overflow in container-type functions. · highb/postgres@9581e26 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9581e26

Browse files
committed
Prevent stack overflow in container-type functions.
A range type can name another range type as its subtype, and a record type can bear a column of another record type. Consequently, functions like range_cmp() and record_recv() are recursive. Functions at risk include operator family members and referents of pg_type regproc columns. Treat as recursive any such function that looks up and calls the same-purpose function for a record column type or the range subtype. Back-patch to 9.0 (all supported versions). An array type's element type is never itself an array type, so array functions are unaffected. Recursion depth proportional to array dimensionality, found in array_dim_to_jsonb(), is fine thanks to MAXDIM.
1 parent 48f6310 commit 9581e26

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/backend/utils/adt/rowtypes.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "catalog/pg_type.h"
2020
#include "funcapi.h"
2121
#include "libpq/pqformat.h"
22+
#include "miscadmin.h"
2223
#include "utils/builtins.h"
2324
#include "utils/lsyscache.h"
2425
#include "utils/typcache.h"
@@ -84,6 +85,8 @@ record_in(PG_FUNCTION_ARGS)
8485
bool *nulls;
8586
StringInfoData buf;
8687

88+
check_stack_depth(); /* recurses for record-type columns */
89+
8790
/*
8891
* Give a friendly error message if we did not get enough info to identify
8992
* the target record type. (lookup_rowtype_tupdesc would fail anyway, but
@@ -307,6 +310,8 @@ record_out(PG_FUNCTION_ARGS)
307310
bool *nulls;
308311
StringInfoData buf;
309312

313+
check_stack_depth(); /* recurses for record-type columns */
314+
310315
/* Extract type info from the tuple itself */
311316
tupType = HeapTupleHeaderGetTypeId(rec);
312317
tupTypmod = HeapTupleHeaderGetTypMod(rec);
@@ -470,6 +475,8 @@ record_recv(PG_FUNCTION_ARGS)
470475
Datum *values;
471476
bool *nulls;
472477

478+
check_stack_depth(); /* recurses for record-type columns */
479+
473480
/*
474481
* Give a friendly error message if we did not get enough info to identify
475482
* the target record type. (lookup_rowtype_tupdesc would fail anyway, but
@@ -662,6 +669,8 @@ record_send(PG_FUNCTION_ARGS)
662669
bool *nulls;
663670
StringInfoData buf;
664671

672+
check_stack_depth(); /* recurses for record-type columns */
673+
665674
/* Extract type info from the tuple itself */
666675
tupType = HeapTupleHeaderGetTypeId(rec);
667676
tupTypmod = HeapTupleHeaderGetTypMod(rec);
@@ -821,6 +830,8 @@ record_cmp(FunctionCallInfo fcinfo)
821830
int i2;
822831
int j;
823832

833+
check_stack_depth(); /* recurses for record-type columns */
834+
824835
/* Extract type info from the tuples */
825836
tupType1 = HeapTupleHeaderGetTypeId(record1);
826837
tupTypmod1 = HeapTupleHeaderGetTypMod(record1);
@@ -1056,6 +1067,8 @@ record_eq(PG_FUNCTION_ARGS)
10561067
int i2;
10571068
int j;
10581069

1070+
check_stack_depth(); /* recurses for record-type columns */
1071+
10591072
/* Extract type info from the tuples */
10601073
tupType1 = HeapTupleHeaderGetTypeId(record1);
10611074
tupTypmod1 = HeapTupleHeaderGetTypMod(record1);

0 commit comments

Comments
 (0)
0