Skip to content
Snippets Groups Projects
Commit 325feaef authored by Andrew Dunstan's avatar Andrew Dunstan
Browse files

Check length of enum literals on definition and input to make sure they will...

Check length of enum literals on definition and input to make sure they will fit in a name field and not cause syscache errors.
parent ffb27446
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/pg_enum.c,v 1.1 2007/04/02 03:49:37 tgl Exp $ * $PostgreSQL: pgsql/src/backend/catalog/pg_enum.c,v 1.2 2007/04/02 22:14:17 adunstan Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -78,6 +78,19 @@ EnumValuesCreate(Oid enumTypeOid, List *vals) ...@@ -78,6 +78,19 @@ EnumValuesCreate(Oid enumTypeOid, List *vals)
{ {
char *lab = strVal(lfirst(lc)); 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); values[Anum_pg_enum_enumtypid - 1] = ObjectIdGetDatum(enumTypeOid);
namestrcpy(&enumlabel, lab); namestrcpy(&enumlabel, lab);
values[Anum_pg_enum_enumlabel - 1] = NameGetDatum(&enumlabel); values[Anum_pg_enum_enumlabel - 1] = NameGetDatum(&enumlabel);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/enum.c,v 1.1 2007/04/02 03:49:39 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/enum.c,v 1.2 2007/04/02 22:14:17 adunstan Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -45,6 +45,15 @@ cstring_enum(char *name, Oid enumtypoid) ...@@ -45,6 +45,15 @@ cstring_enum(char *name, Oid enumtypoid)
HeapTuple tup; HeapTuple tup;
Oid enumoid; 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, tup = SearchSysCache(ENUMTYPOIDNAME,
ObjectIdGetDatum(enumtypoid), ObjectIdGetDatum(enumtypoid),
CStringGetDatum(name), CStringGetDatum(name),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment