diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c index 59e5dc8..65cd5ed 100644 --- a/src/backend/utils/adt/regproc.c +++ b/src/backend/utils/adt/regproc.c @@ -1569,6 +1569,7 @@ Datum regrolein(PG_FUNCTION_ARGS) { char *role_name_or_oid = PG_GETARG_CSTRING(0); + List *names; Oid result; /* '-' ? */ @@ -1586,7 +1587,14 @@ regrolein(PG_FUNCTION_ARGS) } /* Normal case: see if the name matches any pg_authid entry. */ - result = get_role_oid(role_name_or_oid, false); + names = stringToQualifiedNameList(role_name_or_oid); + + if (list_length(names) != 1) + ereport(ERROR, + (errcode(ERRCODE_INVALID_NAME), + errmsg("invalid name syntax"))); + + result = get_role_oid(strVal(linitial(names)), false); PG_RETURN_OID(result); } @@ -1600,9 +1608,17 @@ Datum to_regrole(PG_FUNCTION_ARGS) { char *role_name = PG_GETARG_CSTRING(0); + List *names; Oid result; - result = get_role_oid(role_name, true); + names = stringToQualifiedNameList(role_name); + + if (list_length(names) != 1) + ereport(ERROR, + (errcode(ERRCODE_INVALID_NAME), + errmsg("invalid name syntax"))); + + result = get_role_oid(strVal(linitial(names)), true); if (OidIsValid(result)) PG_RETURN_OID(result); @@ -1668,6 +1684,7 @@ Datum regnamespacein(PG_FUNCTION_ARGS) { char *nsp_name_or_oid = PG_GETARG_CSTRING(0); + List *names; Oid result = InvalidOid; /* '-' ? */ @@ -1685,7 +1702,14 @@ regnamespacein(PG_FUNCTION_ARGS) } /* Normal case: see if the name matches any pg_namespace entry. */ - result = get_namespace_oid(nsp_name_or_oid, false); + names = stringToQualifiedNameList(nsp_name_or_oid); + + if (list_length(names) != 1) + ereport(ERROR, + (errcode(ERRCODE_INVALID_NAME), + errmsg("invalid name syntax"))); + + result = get_namespace_oid(strVal(linitial(names)), false); PG_RETURN_OID(result); } @@ -1699,9 +1723,17 @@ Datum to_regnamespace(PG_FUNCTION_ARGS) { char *nsp_name = PG_GETARG_CSTRING(0); + List *names; Oid result; - result = get_namespace_oid(nsp_name, true); + names = stringToQualifiedNameList(nsp_name); + + if (list_length(names) != 1) + ereport(ERROR, + (errcode(ERRCODE_INVALID_NAME), + errmsg("invalid name syntax"))); + + result = get_namespace_oid(strVal(linitial(names)), true); if (OidIsValid(result)) PG_RETURN_OID(result); diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out index 8c734f4..e67dec0 100644 --- a/src/test/regress/expected/regproc.out +++ b/src/test/regress/expected/regproc.out @@ -137,6 +137,14 @@ SELECT regtype('pg_catalog.int4'); integer (1 row) +SELECT regrole('pg_catalog.regtestrole'); +ERROR: invalid name syntax +LINE 1: SELECT regrole('pg_catalog.regtestrole'); + ^ +SELECT regnamespace('pg_catalog.pg_catalog'); +ERROR: invalid name syntax +LINE 1: SELECT regnamespace('pg_catalog.pg_catalog'); + ^ SELECT to_regoper('pg_catalog.||/'); to_regoper ------------ @@ -167,6 +175,10 @@ SELECT to_regtype('pg_catalog.int4'); integer (1 row) +SELECT to_regrole('pg_catalog.regtestrole'); +ERROR: invalid name syntax +SELECT to_regnamespace('pg_catalog.pg_catalog'); +ERROR: invalid name syntax /* If objects don't exist, raise errors. */ DROP ROLE regtestrole; -- without schemaname diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql index 8edaf15..0f398ea 100644 --- a/src/test/regress/sql/regproc.sql +++ b/src/test/regress/sql/regproc.sql @@ -33,12 +33,16 @@ SELECT regproc('pg_catalog.now'); SELECT regprocedure('pg_catalog.abs(numeric)'); SELECT regclass('pg_catalog.pg_class'); SELECT regtype('pg_catalog.int4'); +SELECT regrole('pg_catalog.regtestrole'); +SELECT regnamespace('pg_catalog.pg_catalog'); SELECT to_regoper('pg_catalog.||/'); SELECT to_regproc('pg_catalog.now'); SELECT to_regprocedure('pg_catalog.abs(numeric)'); SELECT to_regclass('pg_catalog.pg_class'); SELECT to_regtype('pg_catalog.int4'); +SELECT to_regrole('pg_catalog.regtestrole'); +SELECT to_regnamespace('pg_catalog.pg_catalog'); /* If objects don't exist, raise errors. */