postgres.git / summary / log / commit / refs

commit    ea42ccbced4baeff9df9be0cb8ec3e4d42070089
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Mon Mar 08 23:21:51 2021 +0000
First released in: 14.0, 10.17, 11.12, 12.7, 13.3

    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.


src/backend/commands/collationcmds.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c index 7fd7f0fdf81..1742658aad6 100644 --- a/src/backend/commands/collationcmds.c +++ b/src/backend/commands/collationcmds.c @@ -502,14 +502,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 { [parent: 25b13721d41d]