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

Commitf11d253

Browse files
committed
In can_coerce_type, verify that a possible type-coercion function
actually returns the type it is named for.
1 parent7d392f2 commitf11d253

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

‎src/backend/parser/parse_coerce.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.36 2000/03/16 06:35:07 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.37 2000/03/19 00:15:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515
#include"postgres.h"
1616

17-
17+
#include"catalog/pg_proc.h"
1818
#include"optimizer/clauses.h"
1919
#include"parser/parse_coerce.h"
2020
#include"parser/parse_expr.h"
@@ -126,6 +126,12 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
126126

127127
result=transformExpr(pstate, (Node*)n,EXPR_COLUMN_FIRST);
128128

129+
/* safety check that we got the right thing */
130+
if (exprType(result)!=targetTypeId)
131+
elog(ERROR,"coerce_type: conversion function %s produced %s",
132+
typeTypeName(targetType),
133+
typeidTypeName(exprType(result)));
134+
129135
/*
130136
* If the input is a constant, apply the type conversion function
131137
* now instead of delaying to runtime. (We could, of course,
@@ -163,6 +169,7 @@ can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids)
163169
{
164170
inti;
165171
HeapTupleftup;
172+
Form_pg_procpform;
166173
Oidoid_array[FUNC_MAX_ARGS];
167174

168175
/* run through argument list... */
@@ -221,9 +228,10 @@ can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids)
221228
0);
222229
if (!HeapTupleIsValid(ftup))
223230
return false;
224-
/*
225-
* should also check the function return type just to be safe...
226-
*/
231+
/* Make sure the function's result type is as expected, too */
232+
pform= (Form_pg_proc)GETSTRUCT(ftup);
233+
if (pform->prorettype!=targetTypeId)
234+
return false;
227235
}
228236

229237
return true;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp