aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/regproc.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-01-04 01:03:53 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2016-01-04 01:03:53 -0500
commitfb1227af67eae5e97795f7e3563673c6e67d2844 (patch)
treebd4b596047f9d9d37a231a3bab863affdf9c126e /src/backend/utils/adt/regproc.c
parentf47b602df80d7647ca2e71c86f7228b1bf5bf9f3 (diff)
downloadpostgresql-fb1227af67eae5e97795f7e3563673c6e67d2844.tar.gz
postgresql-fb1227af67eae5e97795f7e3563673c6e67d2844.zip
Fix regrole and regnamespace types to honor quoting like other reg* types.
Aside from any consistency arguments, this is logically necessary because the I/O functions for these types also handle numeric OID values. Without a quoting rule it is impossible to distinguish numeric OIDs from role or namespace names that happen to contain only digits. Also change the to_regrole and to_regnamespace functions to dequote their arguments. While not logically essential, this seems like a good idea since the other to_reg* functions do it. Anyone who really wants raw lookup of an uninterpreted name can fall back on the time-honored solution of (SELECT oid FROM pg_namespace WHERE nspname = whatever). Report and patch by Jim Nasby, reviewed by Michael Paquier
Diffstat (limited to 'src/backend/utils/adt/regproc.c')
-rw-r--r--src/backend/utils/adt/regproc.c48
1 files changed, 40 insertions, 8 deletions
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 59e5dc8ddd0..fc939e641ff 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -855,8 +855,7 @@ format_operator_internal(Oid operator_oid, bool force_qualify)
/*
* Would this oper be found (given the right args) by regoperatorin?
- * If not, or if caller explicitly requests it, we need to qualify
- * it.
+ * If not, or if caller explicitly requests it, we need to qualify it.
*/
if (force_qualify || !OperatorIsVisible(operator_oid))
{
@@ -1570,6 +1569,7 @@ regrolein(PG_FUNCTION_ARGS)
{
char *role_name_or_oid = PG_GETARG_CSTRING(0);
Oid result;
+ List *names;
/* '-' ? */
if (strcmp(role_name_or_oid, "-") == 0)
@@ -1586,7 +1586,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);
}
@@ -1601,8 +1608,16 @@ to_regrole(PG_FUNCTION_ARGS)
{
char *role_name = PG_GETARG_CSTRING(0);
Oid result;
+ List *names;
- 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);
@@ -1619,7 +1634,6 @@ regroleout(PG_FUNCTION_ARGS)
Oid roleoid = PG_GETARG_OID(0);
char *result;
-
if (roleoid == InvalidOid)
{
result = pstrdup("-");
@@ -1627,6 +1641,7 @@ regroleout(PG_FUNCTION_ARGS)
}
result = GetUserNameFromId(roleoid, true);
+
if (!result)
{
/* If OID doesn't match any role, return it numerically */
@@ -1668,7 +1683,8 @@ Datum
regnamespacein(PG_FUNCTION_ARGS)
{
char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
- Oid result = InvalidOid;
+ Oid result;
+ List *names;
/* '-' ? */
if (strcmp(nsp_name_or_oid, "-") == 0)
@@ -1685,7 +1701,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);
}
@@ -1700,8 +1723,16 @@ to_regnamespace(PG_FUNCTION_ARGS)
{
char *nsp_name = PG_GETARG_CSTRING(0);
Oid result;
+ List *names;
- 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);
@@ -1725,6 +1756,7 @@ regnamespaceout(PG_FUNCTION_ARGS)
}
result = get_namespace_name(nspid);
+
if (!result)
{
/* If OID doesn't match any namespace, return it numerically */