diff options
author | Noah Misch <noah@leadboat.com> | 2013-06-12 19:49:50 -0400 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2013-06-12 19:49:50 -0400 |
commit | ff53890f687c7f6b2a10db6661e9c32faf832636 (patch) | |
tree | bd1bd5221cc815a5c0169f593292cf81f44542b4 /src/backend/commands/alter.c | |
parent | dc3eb5638349e74a6628130a5101ce866455f4a3 (diff) |
Don't use ordinary NULL-terminated strings as Name datums.
Consumers are entitled to read the full 64 bytes pertaining to a Name;
using a shorter NULL-terminated string leads to reading beyond the end
its allocation; a SIGSEGV is possible. Use the frequent idiom of
copying to a NameData on the stack. New in 9.3, so no back-patch.
Diffstat (limited to 'src/backend/commands/alter.c')
-rw-r--r-- | src/backend/commands/alter.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c index 178c97949dc..bb6c1a46606 100644 --- a/src/backend/commands/alter.c +++ b/src/backend/commands/alter.c @@ -168,6 +168,7 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name) Datum *values; bool *nulls; bool *replaces; + NameData nameattrdata; oldtup = SearchSysCache1(oidCacheId, ObjectIdGetDatum(objectId)); if (!HeapTupleIsValid(oldtup)) @@ -273,7 +274,8 @@ AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name) values = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(Datum)); nulls = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool)); replaces = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool)); - values[Anum_name - 1] = PointerGetDatum(new_name); + namestrcpy(&nameattrdata, new_name); + values[Anum_name - 1] = NameGetDatum(&nameattrdata); replaces[Anum_name - 1] = true; newtup = heap_modify_tuple(oldtup, RelationGetDescr(rel), values, nulls, replaces); |