]> granicus.if.org Git - postgresql/commitdiff
Fix dblink to treat connection names longer than NAMEDATALEN-2 (62 bytes).
authorItagaki Takahiro <itagaki.takahiro@gmail.com>
Thu, 3 Jun 2010 09:38:33 +0000 (09:38 +0000)
committerItagaki Takahiro <itagaki.takahiro@gmail.com>
Thu, 3 Jun 2010 09:38:33 +0000 (09:38 +0000)
Now long names are adjusted with truncate_identifier() and NOTICE messages
are raised if names are actually truncated.

Backported to release 8.0.

contrib/dblink/dblink.c

index abe64f3daec40822b0344a2cf363c5acdf55785d..88f8130fd793b692207fd7cd2bd8d806ef122670 100644 (file)
@@ -8,7 +8,7 @@
  * Darko Prenosil <Darko.Prenosil@finteh.hr>
  * Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
  *
- * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.91 2010/02/26 02:00:32 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.92 2010/06/03 09:38:33 itagaki Exp $
  * Copyright (c) 2001-2010, PostgreSQL Global Development Group
  * ALL RIGHTS RESERVED;
  *
@@ -54,6 +54,7 @@
 #include "nodes/nodes.h"
 #include "nodes/pg_list.h"
 #include "parser/parse_type.h"
+#include "parser/scansup.h"
 #include "utils/acl.h"
 #include "utils/array.h"
 #include "utils/builtins.h"
@@ -2193,13 +2194,13 @@ static remoteConn *
 getConnectionByName(const char *name)
 {
        remoteConnHashEnt *hentry;
-       char            key[NAMEDATALEN];
+       char       *key;
 
        if (!remoteConnHash)
                remoteConnHash = createConnHash();
 
-       MemSet(key, 0, NAMEDATALEN);
-       snprintf(key, NAMEDATALEN - 1, "%s", name);
+       key = pstrdup(name);
+       truncate_identifier(key, strlen(key), true);
        hentry = (remoteConnHashEnt *) hash_search(remoteConnHash,
                                                                                           key, HASH_FIND, NULL);
 
@@ -2225,13 +2226,13 @@ createNewConnection(const char *name, remoteConn *rconn)
 {
        remoteConnHashEnt *hentry;
        bool            found;
-       char            key[NAMEDATALEN];
+       char       *key;
 
        if (!remoteConnHash)
                remoteConnHash = createConnHash();
 
-       MemSet(key, 0, NAMEDATALEN);
-       snprintf(key, NAMEDATALEN - 1, "%s", name);
+       key = pstrdup(name);
+       truncate_identifier(key, strlen(key), true);
        hentry = (remoteConnHashEnt *) hash_search(remoteConnHash, key,
                                                                                           HASH_ENTER, &found);
 
@@ -2249,14 +2250,13 @@ deleteConnection(const char *name)
 {
        remoteConnHashEnt *hentry;
        bool            found;
-       char            key[NAMEDATALEN];
+       char       *key;
 
        if (!remoteConnHash)
                remoteConnHash = createConnHash();
 
-       MemSet(key, 0, NAMEDATALEN);
-       snprintf(key, NAMEDATALEN - 1, "%s", name);
-
+       key = pstrdup(name);
+       truncate_identifier(key, strlen(key), true);
        hentry = (remoteConnHashEnt *) hash_search(remoteConnHash,
                                                                                           key, HASH_REMOVE, &found);
 
@@ -2390,10 +2390,12 @@ get_connect_string(const char *servername)
        StringInfo      buf = makeStringInfo();
        ForeignDataWrapper *fdw;
        AclResult       aclresult;
+       char       *srvname;
 
        /* first gather the server connstr options */
-       if (strlen(servername) < NAMEDATALEN)
-               foreign_server = GetForeignServerByName(servername, true);
+       srvname = pstrdup(servername);
+       truncate_identifier(srvname, strlen(srvname), true);
+       foreign_server = GetForeignServerByName(srvname, true);
 
        if (foreign_server)
        {