diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/catalog/namespace.c | 15 | ||||
-rw-r--r-- | src/backend/parser/parse_func.c | 7 | ||||
-rw-r--r-- | src/backend/parser/parse_type.c | 24 | ||||
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 8 |
4 files changed, 49 insertions, 5 deletions
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c index ac30f77f024..53ba8a3141a 100644 --- a/src/backend/catalog/namespace.c +++ b/src/backend/catalog/namespace.c @@ -753,13 +753,23 @@ RelationIsVisible(Oid relid) /* * TypenameGetTypid + * Wrapper for binary compatibility. + */ +Oid +TypenameGetTypid(const char *typname) +{ + return TypenameGetTypidExtended(typname, true); +} + +/* + * TypenameGetTypidExtended * Try to resolve an unqualified datatype name. * Returns OID if type found in search path, else InvalidOid. * * This is essentially the same as RelnameGetRelid. */ Oid -TypenameGetTypid(const char *typname) +TypenameGetTypidExtended(const char *typname, bool temp_ok) { Oid typid; ListCell *l; @@ -770,6 +780,9 @@ TypenameGetTypid(const char *typname) { Oid namespaceId = lfirst_oid(l); + if (!temp_ok && namespaceId == myTempNamespace) + continue; /* do not look in temp namespace */ + typid = GetSysCacheOid2(TYPENAMENSP, PointerGetDatum(typname), ObjectIdGetDatum(namespaceId)); diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c index 554ca9d8c47..044addd2501 100644 --- a/src/backend/parser/parse_func.c +++ b/src/backend/parser/parse_func.c @@ -1743,7 +1743,12 @@ FuncNameAsType(List *funcname) Oid result; Type typtup; - typtup = LookupTypeName(NULL, makeTypeNameFromNameList(funcname), NULL, false); + /* + * temp_ok=false protects the <refsect1 id="sql-createfunction-security"> + * contract for writing SECURITY DEFINER functions safely. + */ + typtup = LookupTypeNameExtended(NULL, makeTypeNameFromNameList(funcname), + NULL, false, false); if (typtup == NULL) return InvalidOid; diff --git a/src/backend/parser/parse_type.c b/src/backend/parser/parse_type.c index 9db3553d80a..640cb1e153e 100644 --- a/src/backend/parser/parse_type.c +++ b/src/backend/parser/parse_type.c @@ -33,6 +33,18 @@ static int32 typenameTypeMod(ParseState *pstate, const TypeName *typeName, /* * LookupTypeName + * Wrapper for typical case. + */ +Type +LookupTypeName(ParseState *pstate, const TypeName *typeName, + int32 *typmod_p, bool missing_ok) +{ + return LookupTypeNameExtended(pstate, + typeName, typmod_p, true, missing_ok); +} + +/* + * LookupTypeNameExtended * Given a TypeName object, lookup the pg_type syscache entry of the type. * Returns NULL if no such type can be found. If the type is found, * the typmod value represented in the TypeName struct is computed and @@ -51,11 +63,17 @@ static int32 typenameTypeMod(ParseState *pstate, const TypeName *typeName, * found but is a shell, and there is typmod decoration, an error will be * thrown --- this is intentional. * + * If temp_ok is false, ignore types in the temporary namespace. Pass false + * when the caller will decide, using goodness of fit criteria, whether the + * typeName is actually a type or something else. If typeName always denotes + * a type (or denotes nothing), pass true. + * * pstate is only used for error location info, and may be NULL. */ Type -LookupTypeName(ParseState *pstate, const TypeName *typeName, - int32 *typmod_p, bool missing_ok) +LookupTypeNameExtended(ParseState *pstate, + const TypeName *typeName, int32 *typmod_p, + bool temp_ok, bool missing_ok) { Oid typoid; HeapTuple tup; @@ -172,7 +190,7 @@ LookupTypeName(ParseState *pstate, const TypeName *typeName, else { /* Unqualified type name, so search the search path */ - typoid = TypenameGetTypid(typname); + typoid = TypenameGetTypidExtended(typname, temp_ok); } /* If an array reference, return the array type instead */ diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index bef01cde86e..9f7eb2ba9f2 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -8583,6 +8583,14 @@ get_coercion_expr(Node *arg, deparse_context *context, if (!PRETTY_PAREN(context)) appendStringInfoChar(buf, ')'); } + + /* + * Never emit resulttype(arg) functional notation. A pg_proc entry could + * take precedence, and a resulttype in pg_temp would require schema + * qualification that format_type_with_typemod() would usually omit. We've + * standardized on arg::resulttype, but CAST(arg AS resulttype) notation + * would work fine. + */ appendStringInfo(buf, "::%s", format_type_with_typemod(resulttype, resulttypmod)); } |