Check length of enum literals on definition and input to make sure they will fit...
authorAndrew Dunstan <andrew@dunslane.net>
Mon, 2 Apr 2007 22:14:17 +0000 (22:14 +0000)
committerAndrew Dunstan <andrew@dunslane.net>
Mon, 2 Apr 2007 22:14:17 +0000 (22:14 +0000)
src/backend/catalog/pg_enum.c
src/backend/utils/adt/enum.c

index c0332ccfc06b54afc31be4525c2947e4125332ef..3b3567c957338805c1885ff8c09278cdc93c6c2a 100644 (file)
@@ -78,6 +78,19 @@ EnumValuesCreate(Oid enumTypeOid, List *vals)
        {
                char *lab = strVal(lfirst(lc));
 
+               /* 
+                * labels are stored in a name field, for easier syscache lookup, so
+                * check the length to make sure it's within range.
+                */
+
+               if (strlen(lab) > (NAMEDATALEN - 1))
+                       ereport(ERROR,
+                                       (errcode(ERRCODE_INVALID_NAME),
+                                        errmsg("invalid enum label \"%s\", must be %d characters or less",
+                                                       lab,
+                                                       NAMEDATALEN - 1)));
+
+
                values[Anum_pg_enum_enumtypid - 1] = ObjectIdGetDatum(enumTypeOid);
                namestrcpy(&enumlabel, lab);
                values[Anum_pg_enum_enumlabel - 1] = NameGetDatum(&enumlabel);
index 677c0ba6e1cd4fdc57c53a413a0526e6cb2d5610..3197b7e8cb6cac69dd2c6ab8567a4d5850ca90cc 100644 (file)
@@ -45,6 +45,15 @@ cstring_enum(char *name, Oid enumtypoid)
        HeapTuple tup;
        Oid enumoid;
 
+       /* must check length to prevent Assert failure within SearchSysCache */
+
+       if (strlen(name) >= NAMEDATALEN)
+        ereport(ERROR,
+                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+                 errmsg("invalid input value for enum %s: \"%s\"",
+                                               format_type_be(enumtypoid),
+                        name)));
+
        tup = SearchSysCache(ENUMTYPOIDNAME,
                                                 ObjectIdGetDatum(enumtypoid),
                                                 CStringGetDatum(name),