aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-05-03 16:51:45 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-05-03 16:51:45 +0000
commit308f01c304dd5225b9eebc10a34a00d755f92de9 (patch)
tree596a38dfdc2c7df0338a00b51294f92aede8b8fd /src/backend
parenta935e36ae9674f63887cdb7d94e1c31cb08e08c4 (diff)
downloadpostgresql-308f01c304dd5225b9eebc10a34a00d755f92de9.tar.gz
postgresql-308f01c304dd5225b9eebc10a34a00d755f92de9.zip
Change tsearch2 to not use the unsafe practice of creating functions
that return INTERNAL without also having INTERNAL arguments. Since the functions in question aren't meant to be called by hand anyway, I just redeclared them to take 'internal' instead of 'text'. Also add code to ProcedureCreate() to enforce the restriction, as I should have done to start with :-(
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/catalog/pg_proc.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c
index fde65fd109e..7e797fbd4b0 100644
--- a/src/backend/catalog/pg_proc.c
+++ b/src/backend/catalog/pg_proc.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.109 2003/10/03 19:26:49 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.109.2.1 2005/05/03 16:51:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -65,6 +65,8 @@ ProcedureCreate(const char *procedureName,
const Oid *parameterTypes)
{
int i;
+ bool genericParam = false;
+ bool internalParam = false;
Relation rel;
HeapTuple tup;
HeapTuple oldtup;
@@ -94,29 +96,36 @@ ProcedureCreate(const char *procedureName,
/*
* Do not allow return type ANYARRAY or ANYELEMENT unless at least one
- * argument is also ANYARRAY or ANYELEMENT
+ * input argument is ANYARRAY or ANYELEMENT. Also, do not allow
+ * return type INTERNAL unless at least one input argument is INTERNAL.
*/
- if (returnType == ANYARRAYOID || returnType == ANYELEMENTOID)
+ for (i = 0; i < parameterCount; i++)
{
- bool genericParam = false;
-
- for (i = 0; i < parameterCount; i++)
+ switch (parameterTypes[i])
{
- if (parameterTypes[i] == ANYARRAYOID ||
- parameterTypes[i] == ANYELEMENTOID)
- {
+ case ANYARRAYOID:
+ case ANYELEMENTOID:
genericParam = true;
break;
- }
+ case INTERNALOID:
+ internalParam = true;
+ break;
}
-
- if (!genericParam)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
- errmsg("cannot determine result data type"),
- errdetail("A function returning \"anyarray\" or \"anyelement\" must have at least one argument of either type.")));
}
+ if ((returnType == ANYARRAYOID || returnType == ANYELEMENTOID)
+ && !genericParam)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("cannot determine result data type"),
+ errdetail("A function returning \"anyarray\" or \"anyelement\" must have at least one argument of either type.")));
+
+ if (returnType == INTERNALOID && !internalParam)
+ ereport(ERROR,
+ (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
+ errmsg("unsafe use of INTERNAL pseudo-type"),
+ errdetail("A function returning \"internal\" must have at least one \"internal\" argument.")));
+
/* Make sure we have a zero-padded param type array */
MemSet(typev, 0, FUNC_MAX_ARGS * sizeof(Oid));
if (parameterCount > 0)