diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-08-16 18:14:46 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-08-16 18:14:46 +0000 |
commit | 51bc461d59ea10b33528d4614648ed8da9bafef3 (patch) | |
tree | e813f78937b96f3a523360743d9120dc5339ed37 | |
parent | 29e6cedad0cfeb871d939118c4dd1a4297e0461c (diff) | |
download | postgresql-51bc461d59ea10b33528d4614648ed8da9bafef3.tar.gz postgresql-51bc461d59ea10b33528d4614648ed8da9bafef3.zip |
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.
-rw-r--r-- | src/backend/catalog/pg_type.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c index 82a91ca225c..c3097ceca9f 100644 --- a/src/backend/catalog/pg_type.c +++ b/src/backend/catalog/pg_type.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.115.2.1 2009/02/24 01:38:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/pg_type.c,v 1.115.2.2 2009/08/16 18:14:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -622,23 +622,27 @@ TypeRename(Oid typeOid, const char *newTypeName, Oid typeNamespace) char * makeArrayTypeName(const char *typeName, Oid typeNamespace) { - char *arr; - int i; + char *arr = (char *) palloc(NAMEDATALEN); + int namelen = strlen(typeName); Relation pg_type_desc; + int i; /* * The idea is to prepend underscores as needed until we make a name that * doesn't collide with anything... */ - arr = palloc(NAMEDATALEN); - pg_type_desc = heap_open(TypeRelationId, AccessShareLock); for (i = 1; i < NAMEDATALEN - 1; i++) { arr[i - 1] = '_'; - strlcpy(arr + i, typeName, NAMEDATALEN - i); - truncate_identifier(arr, strlen(arr), false); + if (i + namelen < NAMEDATALEN) + strcpy(arr + i, typeName); + else + { + memcpy(arr + i, typeName, NAMEDATALEN - i); + truncate_identifier(arr, NAMEDATALEN, false); + } if (!SearchSysCacheExists(TYPENAMENSP, CStringGetDatum(arr), ObjectIdGetDatum(typeNamespace), |