Skip to content

Commit 8fff8a8

Browse files
committed
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.
1 parent c267ca6 commit 8fff8a8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/backend/commands/collationcmds.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,16 @@ pg_import_system_collations(PG_FUNCTION_ARGS)
521521
Oid nspid = PG_GETARG_OID(0);
522522
int ncreated = 0;
523523

524-
/* silence compiler warning if we have no locale implementation at all */
525-
(void) nspid;
526-
527524
if (!superuser())
528525
ereport(ERROR,
529526
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
530527
(errmsg("must be superuser to import system collations"))));
531528

529+
if (!SearchSysCacheExists1(NAMESPACEOID, ObjectIdGetDatum(nspid)))
530+
ereport(ERROR,
531+
(errcode(ERRCODE_UNDEFINED_SCHEMA),
532+
errmsg("schema with OID %u does not exist", nspid)));
533+
532534
/* Load collations known to libc, using "locale -a" to enumerate them */
533535
#ifdef READ_LOCALE_A_OUTPUT
534536
{

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