aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/statscmds.c
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2018-03-06 13:17:13 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2018-03-06 13:20:40 -0300
commit1ffb63a2a1767c3dd0c7611bed6383bd37bfbce6 (patch)
treed78d3ede9276ad7b5253dd2308c0c8d93ad51ea8 /src/backend/commands/statscmds.c
parent4c831aeaa7bd837c5462df0bf54dc69d3683237a (diff)
downloadpostgresql-1ffb63a2a1767c3dd0c7611bed6383bd37bfbce6.tar.gz
postgresql-1ffb63a2a1767c3dd0c7611bed6383bd37bfbce6.zip
Fix bogus Name assignment in CreateStatistics
Apparently, it doesn't work to use a plain cstring as a Name datum: you may end up having random bytes because of failing to zero the bytes after the terminating \0, as indicated by valgrind. I introduced this bug in 5564c1181548, so backpatch this fix to REL_10_STABLE, like that commit. While at it, fix a slightly misleading comment, pointed out by David Rowley.
Diffstat (limited to 'src/backend/commands/statscmds.c')
-rw-r--r--src/backend/commands/statscmds.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c
index f46ef01134f..c4adfd569ea 100644
--- a/src/backend/commands/statscmds.c
+++ b/src/backend/commands/statscmds.c
@@ -57,6 +57,7 @@ CreateStatistics(CreateStatsStmt *stmt)
int16 attnums[STATS_MAX_DIMENSIONS];
int numcols = 0;
char *namestr;
+ NameData stxname;
Oid statoid;
Oid namespaceId;
Oid stxowner = GetUserId();
@@ -135,7 +136,8 @@ CreateStatistics(CreateStatsStmt *stmt)
* object in the same namespace as the relation, and cons up a name for it.
*/
if (stmt->defnames)
- namespaceId = QualifiedNameGetCreationNamespace(stmt->defnames, &namestr);
+ namespaceId = QualifiedNameGetCreationNamespace(stmt->defnames,
+ &namestr);
else
{
namespaceId = RelationGetNamespace(rel);
@@ -144,6 +146,7 @@ CreateStatistics(CreateStatsStmt *stmt)
"stat",
namespaceId);
}
+ namestrcpy(&stxname, namestr);
/*
* Deal with the possibility that the statistics object already exists.
@@ -307,7 +310,7 @@ CreateStatistics(CreateStatsStmt *stmt)
memset(values, 0, sizeof(values));
memset(nulls, false, sizeof(nulls));
values[Anum_pg_statistic_ext_stxrelid - 1] = ObjectIdGetDatum(relid);
- values[Anum_pg_statistic_ext_stxname - 1] = CStringGetDatum(namestr);
+ values[Anum_pg_statistic_ext_stxname - 1] = NameGetDatum(&stxname);
values[Anum_pg_statistic_ext_stxnamespace - 1] = ObjectIdGetDatum(namespaceId);
values[Anum_pg_statistic_ext_stxowner - 1] = ObjectIdGetDatum(stxowner);
values[Anum_pg_statistic_ext_stxkeys - 1] = PointerGetDatum(stxkeys);