aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/collationcmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-03-08 18:21:51 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2021-03-08 18:21:51 -0500
commit5c06abb9b97b69513a3998cccf89556e73052e02 (patch)
tree49a1031d3208c9c9d346655602905fb445f9d9f4 /src/backend/commands/collationcmds.c
parent6c20bdb2a279086777a3595ab00bcf14671fc5a1 (diff)
downloadpostgresql-5c06abb9b97b69513a3998cccf89556e73052e02.tar.gz
postgresql-5c06abb9b97b69513a3998cccf89556e73052e02.zip
Validate the OID argument of pg_import_system_collations().
"SELECT pg_import_system_collations(0)" caused an assertion failure. With a random nonzero argument --- or indeed with zero, in non-assert builds --- it would happily make pg_collation entries with garbage values of collnamespace. These are harmless as far as I can tell (unless maybe the OID happens to become used for a schema, later on?). In any case this isn't a security issue, since the function is superuser-only. But it seems like a gotcha for unwary DBAs, so let's add a check that the given OID belongs to some schema. Back-patch to v10 where this function was introduced.
Diffstat (limited to 'src/backend/commands/collationcmds.c')
-rw-r--r--src/backend/commands/collationcmds.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c
index a7ee452e192..55a0e24a35a 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -407,14 +407,16 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
Oid nspid = PG_GETARG_OID(0);
int ncreated = 0;
- /* silence compiler warning if we have no locale implementation at all */
- (void) nspid;
-
if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser to import system collations")));
+ if (!SearchSysCacheExists1(NAMESPACEOID, ObjectIdGetDatum(nspid)))
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_SCHEMA),
+ errmsg("schema with OID %u does not exist", nspid)));
+
/* Load collations known to libc, using "locale -a" to enumerate them */
#ifdef READ_LOCALE_A_OUTPUT
{