Add a defense to prevent storing pseudo-type data into index columns.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 14 Oct 2008 21:47:39 +0000 (21:47 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 14 Oct 2008 21:47:39 +0000 (21:47 +0000)
Formerly, the lack of any opclasses that could accept such data was enough
of a defense, but now with a "record" opclass we need to check more carefully.
(You can still use that opclass for an index, but you have to store a named
composite type not an anonymous one.)

src/backend/catalog/index.c

index d312eaef165aaaf08b9ba1cc680676f5d4d0e41b..9a5e342f8b052379b3c545361942f95423594ab6 100644 (file)
@@ -236,6 +236,17 @@ ConstructTupleDescriptor(Relation heapRelation,
                        to->attislocal = true;
 
                        ReleaseSysCache(tuple);
+
+                       /*
+                        * Make sure the expression yields a type that's safe to store in
+                        * an index.  We need this defense because we have index opclasses
+                        * for pseudo-types such as "record", and the actually stored type
+                        * had better be safe; eg, a named composite type is okay, an
+                        * anonymous record type is not.  The test is the same as for
+                        * whether a table column is of a safe type (which is why we
+                        * needn't check for the non-expression case).
+                        */
+                       CheckAttributeType(NameStr(to->attname), to->atttypid);
                }
 
                /*