Prevent copying default collation
authorPeter Eisentraut <peter_e@gmx.net>
Tue, 13 Jun 2017 12:49:41 +0000 (08:49 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Tue, 13 Jun 2017 12:49:41 +0000 (08:49 -0400)
This will not have the desired effect and might lead to crashes when the
copied collation is used.

Reported-by: Tom Lane <tgl@sss.pgh.pa.us>
src/backend/commands/collationcmds.c

index ab702c2479cd966bc232a7d509cd42f8ace3c0e8..91b65b174d3c2c12dd444a3d32530eaee783d122 100644 (file)
@@ -120,6 +120,18 @@ DefineCollation(ParseState *pstate, List *names, List *parameters, bool if_not_e
        collprovider = ((Form_pg_collation) GETSTRUCT(tp))->collprovider;
 
        ReleaseSysCache(tp);
+
+       /*
+        * Copying the "default" collation is not allowed because most code
+        * checks for DEFAULT_COLLATION_OID instead of COLLPROVIDER_DEFAULT,
+        * and so having a second collation with COLLPROVIDER_DEFAULT would
+        * not work and potentially confuse or crash some code.  This could be
+        * fixed with some legwork.
+        */
+       if (collprovider == COLLPROVIDER_DEFAULT)
+           ereport(ERROR,
+                   (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+                    errmsg("collation \"default\" cannot be copied")));
    }
 
    if (localeEl)