summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2019-12-23 12:08:24 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2019-12-23 12:08:24 -0500
commit31dfa40a834177b8e989a59252ee3ce1a3309075 (patch)
tree5bc39764634961233e4024d28ed29c2e648e12cc
parentfd06985cb9e780237c87cef9c27f134eb0abb4d3 (diff)
Prevent a rowtype from being included in itself via a range.
We probably should have thought of this case when ranges were added, but we didn't. (It's not the fault of commit eb51af71f, because ranges didn't exist then.) It's an old bug, so back-patch to all supported branches. Discussion: https://postgr.es/m/7782.1577051475@sss.pgh.pa.us
-rw-r--r--src/backend/catalog/heap.c9
-rw-r--r--src/test/regress/expected/rangetypes.out3
-rw-r--r--src/test/regress/sql/rangetypes.sql3
3 files changed, 15 insertions, 0 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 03d65a2d8a4..ad8fec1d801 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -573,6 +573,15 @@ CheckAttributeType(const char *attname,
containing_rowtypes = list_delete_first(containing_rowtypes);
}
+ else if (att_typtype == TYPTYPE_RANGE)
+ {
+ /*
+ * If it's a range, recurse to check its subtype.
+ */
+ CheckAttributeType(attname, get_range_subtype(atttypid), attcollation,
+ containing_rowtypes,
+ allow_system_table_mods);
+ }
else if (OidIsValid((att_typelem = get_element_type(atttypid))))
{
/*
diff --git a/src/test/regress/expected/rangetypes.out b/src/test/regress/expected/rangetypes.out
index 6fd16bddd18..5ed6ae47ec3 100644
--- a/src/test/regress/expected/rangetypes.out
+++ b/src/test/regress/expected/rangetypes.out
@@ -1375,6 +1375,9 @@ select *, row_to_json(upper(t)) as u from
["(5,6)","(7,8)") | {"a":7,"b":8}
(2 rows)
+-- this must be rejected to avoid self-inclusion issues:
+alter type two_ints add attribute c two_ints_range;
+ERROR: composite type two_ints cannot be made a member of itself
drop type two_ints cascade;
NOTICE: drop cascades to type two_ints_range
--
diff --git a/src/test/regress/sql/rangetypes.sql b/src/test/regress/sql/rangetypes.sql
index 8960add976f..2d0ec8964e6 100644
--- a/src/test/regress/sql/rangetypes.sql
+++ b/src/test/regress/sql/rangetypes.sql
@@ -463,6 +463,9 @@ select *, row_to_json(upper(t)) as u from
(values (two_ints_range(row(1,2), row(3,4))),
(two_ints_range(row(5,6), row(7,8)))) v(t);
+-- this must be rejected to avoid self-inclusion issues:
+alter type two_ints add attribute c two_ints_range;
+
drop type two_ints cascade;
--