On 1/3/16 10:26 PM, Michael Paquier wrote:
Thanks, this is more or less what I... just did..


Sorry, didn't realize you were on it.

+    result = get_namespace_oid(nsp_name, false);
This is incorrect, you should use strVal(linitial(names)) instead.

Yup. Dur.

+    if (list_length(names) > 1)
+        ereport(ERROR,
+                (errcode(ERRCODE_SYNTAX_ERROR),
+            errmsg("improper qualified name (too many dotted names): %s",
+                   NameListToString(names))));
I would just mark that as "Invalid syntax".

Just noticed this... I just copied the same syntax used elsewhere... whoever commits feel free to editorialize...

A couple of tests in regproc.sql would be a good addition as well.

Added. I'm gonna call this good for now. Note this is just against HEAD since I don't have 9.5 setup yet. Presumably the patch should still apply...
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 59e5dc8..529d692 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,15 @@ 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_SYNTAX_ERROR),
+                       errmsg("improper qualified name (too many dotted 
names): %s",
+                                  NameListToString(names))));
+
+       result = get_role_oid(strVal(linitial(names)), false);
 
        PG_RETURN_OID(result);
 }
@@ -1600,9 +1609,18 @@ 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_SYNTAX_ERROR),
+                       errmsg("improper qualified name (too many dotted 
names): %s",
+                                  NameListToString(names))));
+
+       result = get_role_oid(strVal(linitial(names)), true);
 
        if (OidIsValid(result))
                PG_RETURN_OID(result);
@@ -1668,6 +1686,7 @@ Datum
 regnamespacein(PG_FUNCTION_ARGS)
 {
        char       *nsp_name_or_oid = PG_GETARG_CSTRING(0);
+       List       *names;
        Oid                     result = InvalidOid;
 
        /* '-' ? */
@@ -1685,7 +1704,15 @@ 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_SYNTAX_ERROR),
+                       errmsg("improper qualified name (too many dotted 
names): %s",
+                                  NameListToString(names))));
+
+       result = get_namespace_oid(strVal(linitial(names)), false);
 
        PG_RETURN_OID(result);
 }
@@ -1699,9 +1726,18 @@ 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_SYNTAX_ERROR),
+                       errmsg("improper qualified name (too many dotted 
names): %s",
+                                  NameListToString(names))));
+
+       result = get_namespace_oid(strVal(linitial(names)), true);
 
        if (OidIsValid(result))
                PG_RETURN_OID(result);
diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql
index 8edaf15..cb427dc 100644
--- a/src/test/regress/sql/regproc.sql
+++ b/src/test/regress/sql/regproc.sql
@@ -14,7 +14,9 @@ SELECT regprocedure('abs(numeric)');
 SELECT regclass('pg_class');
 SELECT regtype('int4');
 SELECT regrole('regtestrole');
+SELECT regrole('"regtestrole"');
 SELECT regnamespace('pg_catalog');
+SELECT regnamespace('"pg_catalog"');
 
 SELECT to_regoper('||/');
 SELECT to_regoperator('+(int4,int4)');
@@ -23,7 +25,9 @@ SELECT to_regprocedure('abs(numeric)');
 SELECT to_regclass('pg_class');
 SELECT to_regtype('int4');
 SELECT to_regrole('regtestrole');
+SELECT to_regrole('"regtestrole"');
 SELECT to_regnamespace('pg_catalog');
+SELECT to_regnamespace('"pg_catalog"');
 
 -- with schemaname
 
@@ -53,7 +57,11 @@ SELECT regprocedure('absinthe(numeric)');
 SELECT regclass('pg_classes');
 SELECT regtype('int3');
 SELECT regrole('regtestrole');
+SELECT regrole('"regtestrole"');
+SELECT regrole('" with "" "');
 SELECT regnamespace('nonexistent');
+SELECT regnamespace('"nonexistent"');
+SELECT regnamespace('" with "" "');
 
 -- with schemaname
 
@@ -75,7 +83,11 @@ SELECT to_regprocedure('absinthe(numeric)');
 SELECT to_regclass('pg_classes');
 SELECT to_regtype('int3');
 SELECT to_regrole('regtestrole');
+SELECT to_regrole('"regtestrole"');
+SELECT to_regrole('" with "" "');
 SELECT to_regnamespace('nonexistent');
+SELECT to_regnamespace('"nonexistent"');
+SELECT to_regnamespace('" with "" "');
 
 -- with schemaname
 
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to