Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 785cfee

Browse files
committed
Fix incorrect encoding-aware name truncation in makeArrayTypeName().
truncate_identifier won't do anything if the passed-in strlen is already less than NAMEDATALEN, which it always would be given the strlcpy usage. This has been broken since the arrays-of-composite-types code went in. Arguably truncate_identifier is suffering from excessive optimization and should always process the string, but for the moment I'll take the more localized patch. Per bug #4987.
1 parent a05a4b4 commit 785cfee

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/backend/catalog/pg_type.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.126 2009/06/11 14:48:55 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.127 2009/08/16 18:14:34 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -686,23 +686,27 @@ RenameTypeInternal(Oid typeOid, const char *newTypeName, Oid typeNamespace)
686686
char *
687687
makeArrayTypeName(const char *typeName, Oid typeNamespace)
688688
{
689-
char *arr;
690-
int i;
689+
char *arr = (char *) palloc(NAMEDATALEN);
690+
int namelen = strlen(typeName);
691691
Relation pg_type_desc;
692+
int i;
692693

693694
/*
694695
* The idea is to prepend underscores as needed until we make a name that
695696
* doesn't collide with anything...
696697
*/
697-
arr = palloc(NAMEDATALEN);
698-
699698
pg_type_desc = heap_open(TypeRelationId, AccessShareLock);
700699

701700
for (i = 1; i < NAMEDATALEN - 1; i++)
702701
{
703702
arr[i - 1] = '_';
704-
strlcpy(arr + i, typeName, NAMEDATALEN - i);
705-
truncate_identifier(arr, strlen(arr), false);
703+
if (i + namelen < NAMEDATALEN)
704+
strcpy(arr + i, typeName);
705+
else
706+
{
707+
memcpy(arr + i, typeName, NAMEDATALEN - i);
708+
truncate_identifier(arr, NAMEDATALEN, false);
709+
}
706710
if (!SearchSysCacheExists(TYPENAMENSP,
707711
CStringGetDatum(arr),
708712
ObjectIdGetDatum(typeNamespace),

0 commit comments

Comments
 (0)