Skip to content

Commit 1ffb63a

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 4c831ae commit 1ffb63a

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
@@ -57,6 +57,7 @@ CreateStatistics(CreateStatsStmt *stmt)
5757
int16 attnums[STATS_MAX_DIMENSIONS];
5858
int numcols = 0;
5959
char *namestr;
60+
NameData stxname;
6061
Oid statoid;
6162
Oid namespaceId;
6263
Oid stxowner = GetUserId();
@@ -135,7 +136,8 @@ CreateStatistics(CreateStatsStmt *stmt)
135136
* object in the same namespace as the relation, and cons up a name for it.
136137
*/
137138
if (stmt->defnames)
138-
namespaceId = QualifiedNameGetCreationNamespace(stmt->defnames, &namestr);
139+
namespaceId = QualifiedNameGetCreationNamespace(stmt->defnames,
140+
&namestr);
139141
else
140142
{
141143
namespaceId = RelationGetNamespace(rel);
@@ -144,6 +146,7 @@ CreateStatistics(CreateStatsStmt *stmt)
144146
"stat",
145147
namespaceId);
146148
}
149+
namestrcpy(&stxname, namestr);
147150

148151
/*
149152
* Deal with the possibility that the statistics object already exists.
@@ -307,7 +310,7 @@ CreateStatistics(CreateStatsStmt *stmt)
307310
memset(values, 0, sizeof(values));
308311
memset(nulls, false, sizeof(nulls));
309312
values[Anum_pg_statistic_ext_stxrelid - 1] = ObjectIdGetDatum(relid);
310-
values[Anum_pg_statistic_ext_stxname - 1] = CStringGetDatum(namestr);
313+
values[Anum_pg_statistic_ext_stxname - 1] = NameGetDatum(&stxname);
311314
values[Anum_pg_statistic_ext_stxnamespace - 1] = ObjectIdGetDatum(namespaceId);
312315
values[Anum_pg_statistic_ext_stxowner - 1] = ObjectIdGetDatum(stxowner);
313316
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
@@ -2250,7 +2250,8 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
22502250
* transformExtendedStatistics
22512251
* Handle extended statistic objects
22522252
*
2253-
* Right now, there's nothing to do here, so we just copy the list.
2253+
* Right now, there's nothing to do here, so we just append the list to
2254+
* the existing "after" list.
22542255
*/
22552256
static void
22562257
transformExtendedStatistics(CreateStmtContext *cxt)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy