]> granicus.if.org Git - postgresql/commitdiff
Fix ALTER LARGE OBJECT and GRANT ... ON LARGE OBJECT for large OIDs.
authorRobert Haas <rhaas@postgresql.org>
Sun, 13 Jun 2010 17:43:13 +0000 (17:43 +0000)
committerRobert Haas <rhaas@postgresql.org>
Sun, 13 Jun 2010 17:43:13 +0000 (17:43 +0000)
The previous coding failed for OIDs too large to be represented by
a signed integer.

src/backend/catalog/aclchk.c
src/backend/commands/alter.c
src/backend/commands/comment.c
src/backend/parser/gram.y
src/backend/utils/adt/oid.c
src/include/utils/builtins.h

index 025898d1a5aeadfa0e5adfcff0df4070a67ae35d..d0168e7dcdbd669e803dccf6f0c0a90584c4d8f6 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.166 2010/04/05 01:58:03 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.167 2010/06/13 17:43:12 rhaas Exp $
  *
  * NOTES
  *       See acl.h.
@@ -47,6 +47,7 @@
 #include "miscadmin.h"
 #include "parser/parse_func.h"
 #include "utils/acl.h"
+#include "utils/builtins.h"
 #include "utils/fmgroids.h"
 #include "utils/lsyscache.h"
 #include "utils/rel.h"
@@ -647,7 +648,7 @@ objectNamesToOids(GrantObjectType objtype, List *objnames)
                case ACL_OBJECT_LARGEOBJECT:
                        foreach(cell, objnames)
                        {
-                               Oid                     lobjOid = intVal(lfirst(cell));
+                               Oid                     lobjOid = oidparse(lfirst(cell));
 
                                if (!LargeObjectExists(lobjOid))
                                        ereport(ERROR,
index 26a28d55a765b8e147758ade404ce023f630753a..cecdfa5c6d4a4434f0dd005be276487fc335c9b4 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.35 2010/02/26 02:00:37 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.36 2010/06/13 17:43:12 rhaas Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -31,6 +31,7 @@
 #include "parser/parse_clause.h"
 #include "tcop/utility.h"
 #include "utils/acl.h"
+#include "utils/builtins.h"
 #include "utils/lsyscache.h"
 
 
@@ -235,7 +236,7 @@ ExecAlterOwnerStmt(AlterOwnerStmt *stmt)
                        break;
 
                case OBJECT_LARGEOBJECT:
-                       LargeObjectAlterOwner(intVal(linitial(stmt->object)), newowner);
+                       LargeObjectAlterOwner(oidparse(linitial(stmt->object)), newowner);
                        break;
 
                case OBJECT_OPERATOR:
index 2cf8aff6aec1116ca1449e27c61b638864db1310..7fa09c8d2a0ec19bb8749c9fcf44377aa1944cb4 100644 (file)
@@ -7,7 +7,7 @@
  * Copyright (c) 1996-2010, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.114 2010/02/26 02:00:38 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.115 2010/06/13 17:43:12 rhaas Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1404,32 +1404,9 @@ static void
 CommentLargeObject(List *qualname, char *comment)
 {
        Oid                     loid;
-       Node       *node;
 
        Assert(list_length(qualname) == 1);
-       node = (Node *) linitial(qualname);
-
-       switch (nodeTag(node))
-       {
-               case T_Integer:
-                       loid = intVal(node);
-                       break;
-               case T_Float:
-
-                       /*
-                        * Values too large for int4 will be represented as Float
-                        * constants by the lexer.      Accept these if they are valid OID
-                        * strings.
-                        */
-                       loid = DatumGetObjectId(DirectFunctionCall1(oidin,
-                                                                                        CStringGetDatum(strVal(node))));
-                       break;
-               default:
-                       elog(ERROR, "unrecognized node type: %d",
-                                (int) nodeTag(node));
-                       /* keep compiler quiet */
-                       loid = InvalidOid;
-       }
+       loid = oidparse((Node *) linitial(qualname));
 
        /* check that the large object exists */
        if (!LargeObjectExists(loid))
index c75bc825a8d907b51ad75825fe6b24bae1a0dff8..122213a134f907c3faf2ee8f35e18f3455ed5b0e 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.712 2010/05/30 18:10:40 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.713 2010/06/13 17:43:12 rhaas Exp $
  *
  * HISTORY
  *       AUTHOR                        DATE                    MAJOR EVENT
@@ -365,6 +365,7 @@ static TypeName *TableFuncTypeName(List *columns);
 %type <list>   OptCreateAs CreateAsList
 %type <node>   CreateAsElement ctext_expr
 %type <value>  NumericOnly
+%type <list>   NumericOnly_list
 %type <alias>  alias_clause
 %type <sortby> sortby
 %type <ielem>  index_elem
@@ -399,7 +400,6 @@ static TypeName *TableFuncTypeName(List *columns);
 %type <boolean> opt_varying opt_timezone
 
 %type <ival>   Iconst SignedIconst
-%type <list>   Iconst_list
 %type <str>            Sconst comment_text notify_payload
 %type <str>            RoleId opt_granted_by opt_boolean ColId_or_Sconst
 %type <list>   var_list
@@ -2879,6 +2879,10 @@ NumericOnly:
                        | SignedIconst                                          { $$ = makeInteger($1); }
                ;
 
+NumericOnly_list:      NumericOnly                                             { $$ = list_make1($1); }
+                               | NumericOnly_list ',' NumericOnly      { $$ = lappend($1, $3); }
+               ;
+
 /*****************************************************************************
  *
  *             QUERIES :
@@ -4634,7 +4638,7 @@ privilege_target:
                                        n->objs = $2;
                                        $$ = n;
                                }
-                       | LARGE_P OBJECT_P Iconst_list
+                       | LARGE_P OBJECT_P NumericOnly_list
                                {
                                        PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
                                        n->targtype = ACL_TARGET_OBJECT;
@@ -5929,11 +5933,11 @@ AlterOwnerStmt: ALTER AGGREGATE func_name aggr_args OWNER TO RoleId
                                        n->newowner = $7;
                                        $$ = (Node *)n;
                                }
-                       | ALTER LARGE_P OBJECT_P Iconst OWNER TO RoleId
+                       | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleId
                                {
                                        AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
                                        n->objectType = OBJECT_LARGEOBJECT;
-                                       n->object = list_make1(makeInteger($4));
+                                       n->object = list_make1($4);
                                        n->newowner = $7;
                                        $$ = (Node *)n;
                                }
@@ -10755,10 +10759,6 @@ SignedIconst: Iconst                                                           { $$ = $1; }
                        | '-' Iconst                                                    { $$ = - $2; }
                ;
 
-Iconst_list:   Iconst                                          { $$ = list_make1(makeInteger($1)); }
-                               | Iconst_list ',' Iconst        { $$ = lappend($1, makeInteger($3)); }
-               ;
-
 /*
  * Name classification hierarchy.
  *
index 6f59fc5be1f9e6a233449d26c1fbfd885296e0df..ba86625e271182ce96b3838c85abfed1ee415d7b 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/adt/oid.c,v 1.76 2010/01/02 16:57:54 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/adt/oid.c,v 1.77 2010/06/13 17:43:13 rhaas Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -303,6 +303,28 @@ oidvectorsend(PG_FUNCTION_ARGS)
        return array_send(fcinfo);
 }
 
+/*
+ *             oidparse                                - get OID from IConst/FConst node
+ */
+Oid
+oidparse(Node *node)
+{
+       switch (nodeTag(node))
+       {
+               case T_Integer:
+                       return intVal(node);
+               case T_Float:
+                       /*
+                        * Values too large for int4 will be represented as Float constants
+                        * by the lexer.  Accept these if they are valid OID strings.
+                        */
+                       return oidin_subr(strVal(node), NULL);
+               default:
+                       elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
+       }
+       return InvalidOid;              /* keep compiler quiet */
+}
+
 
 /*****************************************************************************
  *      PUBLIC ROUTINES                                                                                                                 *
index e7edc5717f1fd12080af98a17431a66636d9fac1..1fc36d7406150a5e93e047ec54b2d04d305554ed 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.348 2010/02/26 02:01:28 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/builtins.h,v 1.349 2010/06/13 17:43:13 rhaas Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -479,6 +479,7 @@ extern Datum oidvectorle(PG_FUNCTION_ARGS);
 extern Datum oidvectorge(PG_FUNCTION_ARGS);
 extern Datum oidvectorgt(PG_FUNCTION_ARGS);
 extern oidvector *buildoidvector(const Oid *oids, int n);
+extern Oid oidparse(Node *node);
 
 /* pseudotypes.c */
 extern Datum cstring_in(PG_FUNCTION_ARGS);