aboutsummaryrefslogtreecommitdiff
path: root/src
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:21:04 -0300
commite20dd6a13d870f5c98a163031b38ba23753e628c (patch)
treee14664f77ea7caa6998084936a01194e38bb3f4e /src
parent911e6236bab5b1c2240c087e5e8a110acdb724ba (diff)
downloadpostgresql-e20dd6a13d870f5c98a163031b38ba23753e628c.tar.gz
postgresql-e20dd6a13d870f5c98a163031b38ba23753e628c.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')
-rw-r--r--src/backend/commands/statscmds.c7
-rw-r--r--src/backend/parser/parse_utilcmd.c3
2 files changed, 7 insertions, 3 deletions
diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c
index 9f963ddee98..1a989050984 100644
--- a/src/backend/commands/statscmds.c
+++ b/src/backend/commands/statscmds.c
@@ -56,6 +56,7 @@ CreateStatistics(CreateStatsStmt *stmt)
int16 attnums[STATS_MAX_DIMENSIONS];
int numcols = 0;
char *namestr;
+ NameData stxname;
Oid statoid;
Oid namespaceId;
Oid stxowner = GetUserId();
@@ -134,7 +135,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);
@@ -143,6 +145,7 @@ CreateStatistics(CreateStatsStmt *stmt)
"stat",
namespaceId);
}
+ namestrcpy(&stxname, namestr);
/*
* Deal with the possibility that the statistics object already exists.
@@ -306,7 +309,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);
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index ed7b79d4230..b3367f0cd4b 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -2255,7 +2255,8 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
* transformExtendedStatistics
* Handle extended statistic objects
*
- * Right now, there's nothing to do here, so we just copy the list.
+ * Right now, there's nothing to do here, so we just append the list to
+ * the existing "after" list.
*/
static void
transformExtendedStatistics(CreateStmtContext *cxt)