Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit177af51

Browse files
committed
Change tsearch2 to not use the unsafe practice of creating functions
that return INTERNAL without also having INTERNAL arguments. Since thefunctions in question aren't meant to be called by hand anyway, I justredeclared them to take 'internal' instead of 'text'. Also add codeto ProcedureCreate() to enforce the restriction, as I should have doneto start with :-(
1 parent39e54e3 commit177af51

File tree

4 files changed

+57
-38
lines changed

4 files changed

+57
-38
lines changed

‎contrib/tsearch2/gendict/sql.IN

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
SET search_path = public;
22
BEGIN;
33

4-
HASINIT create function dinit_CFG_MODNAME(text)
4+
HASINIT create function dinit_CFG_MODNAME(internal)
55
HASINIT returns internal
66
HASINIT as 'MODULE_PATHNAME'
77
HASINIT language 'C';

‎contrib/tsearch2/tsearch.sql.in

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ CREATE FUNCTION set_curdict(text)
4444
with (isstrict);
4545

4646
--built-in dictionaries
47-
CREATE FUNCTION dex_init(text)
47+
CREATE FUNCTION dex_init(internal)
4848
returns internal
4949
as 'MODULE_PATHNAME'
5050
language 'C';
@@ -57,13 +57,13 @@ CREATE FUNCTION dex_lexize(internal,internal,int4)
5757

5858
insert into pg_ts_dict select
5959
'simple',
60-
'dex_init(text)',
60+
'dex_init(internal)',
6161
null,
6262
'dex_lexize(internal,internal,int4)',
6363
'Simple example of dictionary.'
6464
;
6565

66-
CREATE FUNCTION snb_en_init(text)
66+
CREATE FUNCTION snb_en_init(internal)
6767
returns internal
6868
as 'MODULE_PATHNAME'
6969
language 'C';
@@ -76,26 +76,26 @@ CREATE FUNCTION snb_lexize(internal,internal,int4)
7676

7777
insert into pg_ts_dict select
7878
'en_stem',
79-
'snb_en_init(text)',
79+
'snb_en_init(internal)',
8080
'contrib/english.stop',
8181
'snb_lexize(internal,internal,int4)',
8282
'English Stemmer. Snowball.'
8383
;
8484

85-
CREATE FUNCTION snb_ru_init(text)
85+
CREATE FUNCTION snb_ru_init(internal)
8686
returns internal
8787
as 'MODULE_PATHNAME'
8888
language 'C';
8989

9090
insert into pg_ts_dict select
9191
'ru_stem',
92-
'snb_ru_init(text)',
92+
'snb_ru_init(internal)',
9393
'contrib/russian.stop',
9494
'snb_lexize(internal,internal,int4)',
9595
'Russian Stemmer. Snowball.'
9696
;
9797

98-
CREATE FUNCTION spell_init(text)
98+
CREATE FUNCTION spell_init(internal)
9999
returns internal
100100
as 'MODULE_PATHNAME'
101101
language 'C';
@@ -108,13 +108,13 @@ CREATE FUNCTION spell_lexize(internal,internal,int4)
108108

109109
insert into pg_ts_dict select
110110
'ispell_template',
111-
'spell_init(text)',
111+
'spell_init(internal)',
112112
null,
113113
'spell_lexize(internal,internal,int4)',
114114
'ISpell interface. Must have .dict and .aff files'
115115
;
116116

117-
CREATE FUNCTION syn_init(text)
117+
CREATE FUNCTION syn_init(internal)
118118
returns internal
119119
as 'MODULE_PATHNAME'
120120
language 'C';
@@ -127,7 +127,7 @@ CREATE FUNCTION syn_lexize(internal,internal,int4)
127127

128128
insert into pg_ts_dict select
129129
'synonym',
130-
'syn_init(text)',
130+
'syn_init(internal)',
131131
null,
132132
'syn_lexize(internal,internal,int4)',
133133
'Example of synonym dictionary'

‎contrib/tsearch2/untsearch.sql.in

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ DROP FUNCTION lexize(text, text);
3434
DROP FUNCTION lexize(text);
3535
DROP FUNCTION set_curdict(int);
3636
DROP FUNCTION set_curdict(text);
37-
DROP FUNCTION dex_init(text);
37+
DROP FUNCTION dex_init(internal);
3838
DROP FUNCTION dex_lexize(internal,internal,int4);
39-
DROP FUNCTION snb_en_init(text);
39+
DROP FUNCTION snb_en_init(internal);
4040
DROP FUNCTION snb_lexize(internal,internal,int4);
41-
DROP FUNCTION snb_ru_init(text);
42-
DROP FUNCTION spell_init(text);
41+
DROP FUNCTION snb_ru_init(internal);
42+
DROP FUNCTION spell_init(internal);
4343
DROP FUNCTION spell_lexize(internal,internal,int4);
44-
DROP FUNCTION syn_init(text);
44+
DROP FUNCTION syn_init(internal);
4545
DROP FUNCTION syn_lexize(internal,internal,int4);
4646
DROP FUNCTION set_curprs(int);
4747
DROP FUNCTION set_curprs(text);

‎src/backend/catalog/pg_proc.c

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.128 2005/04/14 20:03:23 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.129 2005/05/03 16:51:00 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -81,6 +81,9 @@ ProcedureCreate(const char *procedureName,
8181
intallParamCount;
8282
Oid*allParams;
8383
boolgenericInParam= false;
84+
boolgenericOutParam= false;
85+
boolinternalInParam= false;
86+
boolinternalOutParam= false;
8487
Relationrel;
8588
HeapTupletup;
8689
HeapTupleoldtup;
@@ -133,43 +136,59 @@ ProcedureCreate(const char *procedureName,
133136

134137
/*
135138
* Do not allow return type ANYARRAY or ANYELEMENT unless at least one
136-
* input argument is also ANYARRAY or ANYELEMENT
139+
* input argument is ANYARRAY or ANYELEMENT. Also, do not allow
140+
* return type INTERNAL unless at least one input argument is INTERNAL.
137141
*/
138142
for (i=0;i<parameterCount;i++)
139143
{
140-
if (parameterTypes->values[i]==ANYARRAYOID||
141-
parameterTypes->values[i]==ANYELEMENTOID)
144+
switch (parameterTypes->values[i])
142145
{
143-
genericInParam= true;
144-
break;
146+
caseANYARRAYOID:
147+
caseANYELEMENTOID:
148+
genericInParam= true;
149+
break;
150+
caseINTERNALOID:
151+
internalInParam= true;
152+
break;
145153
}
146154
}
147155

148-
if (!genericInParam)
156+
if (allParameterTypes!=PointerGetDatum(NULL))
149157
{
150-
boolgenericOutParam= false;
151-
152-
if (allParameterTypes!=PointerGetDatum(NULL))
158+
for (i=0;i<allParamCount;i++)
153159
{
154-
for (i=0;i<allParamCount;i++)
160+
/*
161+
* We don't bother to distinguish input and output params here,
162+
* so if there is, say, just an input INTERNAL param then we will
163+
* still set internalOutParam. This is OK since we don't really
164+
* care.
165+
*/
166+
switch (allParams[i])
155167
{
156-
if (allParams[i]==ANYARRAYOID||
157-
allParams[i]==ANYELEMENTOID)
158-
{
168+
caseANYARRAYOID:
169+
caseANYELEMENTOID:
159170
genericOutParam= true;
160171
break;
161-
}
172+
caseINTERNALOID:
173+
internalOutParam= true;
174+
break;
162175
}
163176
}
164-
165-
if (returnType==ANYARRAYOID||returnType==ANYELEMENTOID||
166-
genericOutParam)
167-
ereport(ERROR,
168-
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
169-
errmsg("cannot determine result data type"),
170-
errdetail("A function returning \"anyarray\" or \"anyelement\" must have at least one argument of either type.")));
171177
}
172178

179+
if ((returnType==ANYARRAYOID||returnType==ANYELEMENTOID||
180+
genericOutParam)&& !genericInParam)
181+
ereport(ERROR,
182+
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
183+
errmsg("cannot determine result data type"),
184+
errdetail("A function returning \"anyarray\" or \"anyelement\" must have at least one argument of either type.")));
185+
186+
if ((returnType==INTERNALOID||internalOutParam)&& !internalInParam)
187+
ereport(ERROR,
188+
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
189+
errmsg("unsafe use of INTERNAL pseudo-type"),
190+
errdetail("A function returning \"internal\" must have at least one \"internal\" argument.")));
191+
173192
/*
174193
* don't allow functions of complex types that have the same name as
175194
* existing attributes of the type

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp