]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Prevent a rowtype from being included in itself via a range.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 23 Dec 2019 17:08:24 +0000 (12:08 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 23 Dec 2019 17:08:24 +0000 (12:08 -0500)
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

src/backend/catalog/heap.c
src/test/regress/expected/rangetypes.out
src/test/regress/sql/rangetypes.sql

index eea1638a2e6d3d0d5081978954522435968175a5..79de6d71c6970400e5bf7fba0fb75915767ae0d0 100644 (file)
@@ -564,6 +564,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))))
        {
                /*
index 49432efa1a27ee3e8b118b26238a990a1244be48..fcb9335bce344639fec141afb42558dfaa1e9454 100644 (file)
@@ -1376,6 +1376,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
 --
index 8960add976f4d70c22c314b1cb27417c363d9370..2d0ec8964e6768870d2e154176622c8a41cf0f0d 100644 (file)
@@ -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;
 
 --