Content-Length: 345045 | pFad | http://github.com/postgres/postgres/commit/0398e071adf5437bafaab7701dc46df55dceca76

86 Prevent stack overflow in container-type functions. · postgres/postgres@0398e07 · GitHub
Skip to content

Commit 0398e07

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 188e081 commit 0398e07

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"
@@ -88,6 +89,8 @@ record_in(PG_FUNCTION_ARGS)
8889
bool *nulls;
8990
StringInfoData buf;
9091

92+
check_stack_depth(); /* recurses for record-type columns */
93+
9194
/*
9295
* Use the passed type unless it's RECORD; we can't support input of
9396
* anonymous types, mainly because there's no good way to figure out which
@@ -310,6 +313,8 @@ record_out(PG_FUNCTION_ARGS)
310313
bool *nulls;
311314
StringInfoData buf;
312315

316+
check_stack_depth(); /* recurses for record-type columns */
317+
313318
/* Extract type info from the tuple itself */
314319
tupType = HeapTupleHeaderGetTypeId(rec);
315320
tupTypmod = HeapTupleHeaderGetTypMod(rec);
@@ -477,6 +482,8 @@ record_recv(PG_FUNCTION_ARGS)
477482
Datum *values;
478483
bool *nulls;
479484

485+
check_stack_depth(); /* recurses for record-type columns */
486+
480487
/*
481488
* Use the passed type unless it's RECORD; we can't support input of
482489
* anonymous types, mainly because there's no good way to figure out which
@@ -667,6 +674,8 @@ record_send(PG_FUNCTION_ARGS)
667674
bool *nulls;
668675
StringInfoData buf;
669676

677+
check_stack_depth(); /* recurses for record-type columns */
678+
670679
/* Extract type info from the tuple itself */
671680
tupType = HeapTupleHeaderGetTypeId(rec);
672681
tupTypmod = HeapTupleHeaderGetTypMod(rec);
@@ -826,6 +835,8 @@ record_cmp(FunctionCallInfo fcinfo)
826835
int i2;
827836
int j;
828837

838+
check_stack_depth(); /* recurses for record-type columns */
839+
829840
/* Extract type info from the tuples */
830841
tupType1 = HeapTupleHeaderGetTypeId(record1);
831842
tupTypmod1 = HeapTupleHeaderGetTypMod(record1);
@@ -1052,6 +1063,8 @@ record_eq(PG_FUNCTION_ARGS)
10521063
int i2;
10531064
int j;
10541065

1066+
check_stack_depth(); /* recurses for record-type columns */
1067+
10551068
/* Extract type info from the tuples */
10561069
tupType1 = HeapTupleHeaderGetTypeId(record1);
10571070
tupTypmod1 = HeapTupleHeaderGetTypMod(record1);

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgres/postgres/commit/0398e071adf5437bafaab7701dc46df55dceca76

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy