diff options
author | Noah Misch <noah@leadboat.com> | 2019-08-05 07:48:41 -0700 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2019-08-05 07:48:45 -0700 |
commit | 752fa3dbfc36c70a692986b56daac41410fca3f6 (patch) | |
tree | 57569a9b106aa92376f0a11b2a23ac506a10f192 /src/backend/parser | |
parent | 0e9e7e28902ca0a01b0d36cbdd155abe4ea63cfe (diff) | |
download | postgresql-752fa3dbfc36c70a692986b56daac41410fca3f6.tar.gz postgresql-752fa3dbfc36c70a692986b56daac41410fca3f6.zip |
Require the schema qualification in pg_temp.type_name(arg).
Commit aa27977fe21a7dfa4da4376ad66ae37cb8f0d0b5 introduced this
restriction for pg_temp.function_name(arg); do likewise for types
created in temporary schemas. Programs that this breaks should add
"pg_temp." schema qualification or switch to arg::type_name syntax.
Back-patch to 9.4 (all supported versions).
Reviewed by Tom Lane. Reported by Tom Lane.
Security: CVE-2019-10208
Diffstat (limited to 'src/backend/parser')
-rw-r--r-- | src/backend/parser/parse_func.c | 7 | ||||
-rw-r--r-- | src/backend/parser/parse_type.c | 24 |
2 files changed, 27 insertions, 4 deletions
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 */ |