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

Commit e20dd6a

Browse files
committed
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 5564c11, so backpatch this fix to REL_10_STABLE, like that commit. While at it, fix a slightly misleading comment, pointed out by David Rowley.
1 parent 911e623 commit e20dd6a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/backend/commands/statscmds.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ CreateStatistics(CreateStatsStmt *stmt)
5656
int16 attnums[STATS_MAX_DIMENSIONS];
5757
int numcols = 0;
5858
char *namestr;
59+
NameData stxname;
5960
Oid statoid;
6061
Oid namespaceId;
6162
Oid stxowner = GetUserId();
@@ -134,7 +135,8 @@ CreateStatistics(CreateStatsStmt *stmt)
134135
* object in the same namespace as the relation, and cons up a name for it.
135136
*/
136137
if (stmt->defnames)
137-
namespaceId = QualifiedNameGetCreationNamespace(stmt->defnames, &namestr);
138+
namespaceId = QualifiedNameGetCreationNamespace(stmt->defnames,
139+
&namestr);
138140
else
139141
{
140142
namespaceId = RelationGetNamespace(rel);
@@ -143,6 +145,7 @@ CreateStatistics(CreateStatsStmt *stmt)
143145
"stat",
144146
namespaceId);
145147
}
148+
namestrcpy(&stxname, namestr);
146149

147150
/*
148151
* Deal with the possibility that the statistics object already exists.
@@ -306,7 +309,7 @@ CreateStatistics(CreateStatsStmt *stmt)
306309
memset(values, 0, sizeof(values));
307310
memset(nulls, false, sizeof(nulls));
308311
values[Anum_pg_statistic_ext_stxrelid - 1] = ObjectIdGetDatum(relid);
309-
values[Anum_pg_statistic_ext_stxname - 1] = CStringGetDatum(namestr);
312+
values[Anum_pg_statistic_ext_stxname - 1] = NameGetDatum(&stxname);
310313
values[Anum_pg_statistic_ext_stxnamespace - 1] = ObjectIdGetDatum(namespaceId);
311314
values[Anum_pg_statistic_ext_stxowner - 1] = ObjectIdGetDatum(stxowner);
312315
values[Anum_pg_statistic_ext_stxkeys - 1] = PointerGetDatum(stxkeys);

src/backend/parser/parse_utilcmd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2255,7 +2255,8 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
22552255
* transformExtendedStatistics
22562256
* Handle extended statistic objects
22572257
*
2258-
* Right now, there's nothing to do here, so we just copy the list.
2258+
* Right now, there's nothing to do here, so we just append the list to
2259+
* the existing "after" list.
22592260
*/
22602261
static void
22612262
transformExtendedStatistics(CreateStmtContext *cxt)

0 commit comments

Comments
 (0)