Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit325feae

Browse files
committed
Check length of enum literals on definition and input to make sure they will fit in a name field and not cause syscache errors.
1 parentffb2744 commit325feae

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

‎src/backend/catalog/pg_enum.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/catalog/pg_enum.c,v 1.1 2007/04/0203:49:37 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/catalog/pg_enum.c,v 1.2 2007/04/0222:14:17 adunstan Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -78,6 +78,19 @@ EnumValuesCreate(Oid enumTypeOid, List *vals)
7878
{
7979
char*lab=strVal(lfirst(lc));
8080

81+
/*
82+
* labels are stored in a name field, for easier syscache lookup, so
83+
* check the length to make sure it's within range.
84+
*/
85+
86+
if (strlen(lab)> (NAMEDATALEN-1))
87+
ereport(ERROR,
88+
(errcode(ERRCODE_INVALID_NAME),
89+
errmsg("invalid enum label \"%s\", must be %d characters or less",
90+
lab,
91+
NAMEDATALEN-1)));
92+
93+
8194
values[Anum_pg_enum_enumtypid-1]=ObjectIdGetDatum(enumTypeOid);
8295
namestrcpy(&enumlabel,lab);
8396
values[Anum_pg_enum_enumlabel-1]=NameGetDatum(&enumlabel);

‎src/backend/utils/adt/enum.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/adt/enum.c,v 1.1 2007/04/0203:49:39 tgl Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/adt/enum.c,v 1.2 2007/04/0222:14:17 adunstan Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -45,6 +45,15 @@ cstring_enum(char *name, Oid enumtypoid)
4545
HeapTupletup;
4646
Oidenumoid;
4747

48+
/* must check length to prevent Assert failure within SearchSysCache */
49+
50+
if (strlen(name) >=NAMEDATALEN)
51+
ereport(ERROR,
52+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
53+
errmsg("invalid input value for enum %s: \"%s\"",
54+
format_type_be(enumtypoid),
55+
name)));
56+
4857
tup=SearchSysCache(ENUMTYPOIDNAME,
4958
ObjectIdGetDatum(enumtypoid),
5059
CStringGetDatum(name),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp