aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/functioncmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-10-04 22:08:44 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-10-04 22:08:44 +0000
commitd2db166c7527552cc0ee6121fb32d11e14d36e97 (patch)
tree0f35f6fe990922ffd7c0ce68f746e4ef709872ac /src/backend/commands/functioncmds.c
parent04c57d68ce391847d6db9c3f96eaca365e296105 (diff)
downloadpostgresql-d2db166c7527552cc0ee6121fb32d11e14d36e97.tar.gz
postgresql-d2db166c7527552cc0ee6121fb32d11e14d36e97.zip
Require superuser privilege to create a binary-compatible cast, per
discussion some weeks ago. Also, add a check that two types to be binary-equivalenced match as to typlen, typbyval, and typalign; if they don't then it's surely a mistake to equivalence them.
Diffstat (limited to 'src/backend/commands/functioncmds.c')
-rw-r--r--src/backend/commands/functioncmds.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 7857eb3bb3f..01217d9b128 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.22 2002/09/21 18:39:25 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.23 2002/10/04 22:08:44 tgl Exp $
*
* DESCRIPTION
* These routines take the parse tree and pick out the
@@ -756,8 +756,35 @@ CreateCast(CreateCastStmt *stmt)
}
else
{
+ int16 typ1len;
+ int16 typ2len;
+ bool typ1byval;
+ bool typ2byval;
+ char typ1align;
+ char typ2align;
+
/* indicates binary coercibility */
funcid = InvalidOid;
+
+ /*
+ * Must be superuser to create binary-compatible casts, since
+ * erroneous casts can easily crash the backend.
+ */
+ if (!superuser())
+ elog(ERROR, "Must be superuser to create a cast WITHOUT FUNCTION");
+
+ /*
+ * Also, insist that the types match as to size, alignment, and
+ * pass-by-value attributes; this provides at least a crude check
+ * that they have similar representations. A pair of types that
+ * fail this test should certainly not be equated.
+ */
+ get_typlenbyvalalign(sourcetypeid, &typ1len, &typ1byval, &typ1align);
+ get_typlenbyvalalign(targettypeid, &typ2len, &typ2byval, &typ2align);
+ if (typ1len != typ2len ||
+ typ1byval != typ2byval ||
+ typ1align != typ2align)
+ elog(ERROR, "source and target datatypes are not physically compatible");
}
/* convert CoercionContext enum to char value for castcontext */