diff --git a/src/backend/utils/adt/domains.c b/src/backend/utils/adt/domains.c index 19ee4ce..cea1329 100644 --- a/src/backend/utils/adt/domains.c +++ b/src/backend/utils/adt/domains.c @@ -73,17 +73,21 @@ domain_state_setup(Oid domainType, bool binary, MemoryContext mcxt) { DomainIOData *my_extra; Oid baseType; + TypeCacheEntry *typentry; + + /* Validate the input domain type */ + typentry = lookup_type_cache(domainType, TYPECACHE_DOMAIN_INFO); + if (typentry->typtype != TYPTYPE_DOMAIN) + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("type %s is not a domain", + format_type_be(domainType)))); my_extra = (DomainIOData *) MemoryContextAlloc(mcxt, sizeof(DomainIOData)); /* Find out the base type */ my_extra->typtypmod = -1; baseType = getBaseTypeAndTypmod(domainType, &my_extra->typtypmod); - if (baseType == domainType) - ereport(ERROR, - (errcode(ERRCODE_DATATYPE_MISMATCH), - errmsg("type %s is not a domain", - format_type_be(domainType)))); /* Look up underlying I/O function */ if (binary) diff --git a/src/backend/utils/cache/typcache.c b/src/backend/utils/cache/typcache.c index 9150fe8..4aa32b5 100644 --- a/src/backend/utils/cache/typcache.c +++ b/src/backend/utils/cache/typcache.c @@ -231,7 +231,10 @@ lookup_type_cache(Oid type_id, int flags) tp = SearchSysCache1(TYPEOID, ObjectIdGetDatum(type_id)); if (!HeapTupleIsValid(tp)) - elog(ERROR, "cache lookup failed for type %u", type_id); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_OBJECT), + errmsg("type with OID %u does not exist", + type_id))); typtup = (Form_pg_type) GETSTRUCT(tp); if (!typtup->typisdefined) ereport(ERROR, diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c index 7aae350..c50a0b4 100644 --- a/src/backend/utils/fmgr/fmgr.c +++ b/src/backend/utils/fmgr/fmgr.c @@ -2458,7 +2458,9 @@ CheckFunctionValidatorAccess(Oid validatorOid, Oid functionOid) /* Get the function's pg_proc entry */ procTup = SearchSysCache1(PROCOID, ObjectIdGetDatum(functionOid)); if (!HeapTupleIsValid(procTup)) - elog(ERROR, "cache lookup failed for function %u", functionOid); + ereport(ERROR, + (errcode(ERRCODE_UNDEFINED_FUNCTION), + errmsg("function with OID %u does not exist", functionOid))); procStruct = (Form_pg_proc) GETSTRUCT(procTup); /* diff --git a/src/test/regress/expected/errors.out b/src/test/regress/expected/errors.out index 210e5ff..48e2e29 100644 --- a/src/test/regress/expected/errors.out +++ b/src/test/regress/expected/errors.out @@ -447,3 +447,16 @@ create function infinite_recurse() returns int as \set VERBOSITY terse select infinite_recurse(); ERROR: stack depth limit exceeded +-- +-- Test error message by calling functions with invalid OID. +-- should get an appropriate error not cache lookup failure error +-- +-- passing invalid OID (1) to record_in +select pg_catalog.record_in(cast(pg_catalog.numerictypmodout(cast(98 as integer)) as cstring), cast(1 as oid), cast(35 as integer)); +ERROR: type with OID 1 does not exist +--passing invalid OID(10) to fmgr_c_validator +select pg_catalog.fmgr_c_validator(10); +ERROR: function with OID 10 does not exist +--passing invalid OID(10) to pg_catalog.domain_in +select pg_catalog.domain_in(cast(null as cstring),cast(10 as oid),cast(53 as integer)); +ERROR: type with OID 10 does not exist diff --git a/src/test/regress/sql/errors.sql b/src/test/regress/sql/errors.sql index cd370b4..5a3f3ff 100644 --- a/src/test/regress/sql/errors.sql +++ b/src/test/regress/sql/errors.sql @@ -371,3 +371,17 @@ create function infinite_recurse() returns int as 'select infinite_recurse()' language sql; \set VERBOSITY terse select infinite_recurse(); + +-- +-- Test error message by calling functions with invalid OID. +-- should get an appropriate error not cache lookup failure error +-- + +-- passing invalid OID (1) to record_in +select pg_catalog.record_in(cast(pg_catalog.numerictypmodout(cast(98 as integer)) as cstring), cast(1 as oid), cast(35 as integer)); + +--passing invalid OID(10) to fmgr_c_validator +select pg_catalog.fmgr_c_validator(10); + +--passing invalid OID(10) to pg_catalog.domain_in +select pg_catalog.domain_in(cast(null as cstring),cast(10 as oid),cast(53 as integer));