mirror of
https://github.com/postgres/postgres.git
synced 2025-05-17 06:41:24 +03:00
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 :-(
This commit is contained in:
parent
a935e36ae9
commit
308f01c304
@ -1,7 +1,7 @@
|
||||
SET search_path = public;
|
||||
BEGIN;
|
||||
|
||||
HASINIT create function dinit_CFG_MODNAME(text)
|
||||
HASINIT create function dinit_CFG_MODNAME(internal)
|
||||
HASINIT returns internal
|
||||
HASINIT as 'MODULE_PATHNAME'
|
||||
HASINIT language 'C';
|
||||
|
@ -44,7 +44,7 @@ CREATE FUNCTION set_curdict(text)
|
||||
with (isstrict);
|
||||
|
||||
--built-in dictionaries
|
||||
CREATE FUNCTION dex_init(text)
|
||||
CREATE FUNCTION dex_init(internal)
|
||||
returns internal
|
||||
as 'MODULE_PATHNAME'
|
||||
language 'C';
|
||||
@ -63,7 +63,7 @@ insert into pg_ts_dict select
|
||||
'Simple example of dictionary.'
|
||||
;
|
||||
|
||||
CREATE FUNCTION snb_en_init(text)
|
||||
CREATE FUNCTION snb_en_init(internal)
|
||||
returns internal
|
||||
as 'MODULE_PATHNAME'
|
||||
language 'C';
|
||||
@ -82,7 +82,7 @@ insert into pg_ts_dict select
|
||||
'English Stemmer. Snowball.'
|
||||
;
|
||||
|
||||
CREATE FUNCTION snb_ru_init(text)
|
||||
CREATE FUNCTION snb_ru_init(internal)
|
||||
returns internal
|
||||
as 'MODULE_PATHNAME'
|
||||
language 'C';
|
||||
@ -95,7 +95,7 @@ insert into pg_ts_dict select
|
||||
'Russian Stemmer. Snowball.'
|
||||
;
|
||||
|
||||
CREATE FUNCTION spell_init(text)
|
||||
CREATE FUNCTION spell_init(internal)
|
||||
returns internal
|
||||
as 'MODULE_PATHNAME'
|
||||
language 'C';
|
||||
@ -114,7 +114,7 @@ insert into pg_ts_dict select
|
||||
'ISpell interface. Must have .dict and .aff files'
|
||||
;
|
||||
|
||||
CREATE FUNCTION syn_init(text)
|
||||
CREATE FUNCTION syn_init(internal)
|
||||
returns internal
|
||||
as 'MODULE_PATHNAME'
|
||||
language 'C';
|
||||
|
@ -34,14 +34,14 @@ DROP FUNCTION lexize(text, text);
|
||||
DROP FUNCTION lexize(text);
|
||||
DROP FUNCTION set_curdict(int);
|
||||
DROP FUNCTION set_curdict(text);
|
||||
DROP FUNCTION dex_init(text);
|
||||
DROP FUNCTION dex_init(internal);
|
||||
DROP FUNCTION dex_lexize(internal,internal,int4);
|
||||
DROP FUNCTION snb_en_init(text);
|
||||
DROP FUNCTION snb_en_init(internal);
|
||||
DROP FUNCTION snb_lexize(internal,internal,int4);
|
||||
DROP FUNCTION snb_ru_init(text);
|
||||
DROP FUNCTION spell_init(text);
|
||||
DROP FUNCTION snb_ru_init(internal);
|
||||
DROP FUNCTION spell_init(internal);
|
||||
DROP FUNCTION spell_lexize(internal,internal,int4);
|
||||
DROP FUNCTION syn_init(text);
|
||||
DROP FUNCTION syn_init(internal);
|
||||
DROP FUNCTION syn_lexize(internal,internal,int4);
|
||||
DROP FUNCTION set_curprs(int);
|
||||
DROP FUNCTION set_curprs(text);
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user