Fix dblink to treat connection names longer than NAMEDATALEN-2 (62 bytes).
authorItagaki Takahiro <[email protected]>
Thu, 3 Jun 2010 09:41:26 +0000 (09:41 +0000)
committerItagaki Takahiro <[email protected]>
Thu, 3 Jun 2010 09:41:26 +0000 (09:41 +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 1360c7a00dc0f4540b35ec85f16ae29ee4ae73cb..5f5e652cfcc537fa993aaf8bc1446cfc13772037 100644 (file)
@@ -8,7 +8,7 @@
  * Darko Prenosil <[email protected]>
  * Shridhar Daithankar <[email protected]>
  *
- * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.69.2.3 2010/02/03 23:01:34 joe Exp $
+ * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.69.2.4 2010/06/03 09:41:26 itagaki Exp $
  * Copyright (c) 2001-2008, PostgreSQL Global Development Group
  * ALL RIGHTS RESERVED;
  *
@@ -52,6 +52,7 @@
 #include "nodes/nodes.h"
 #include "nodes/pg_list.h"
 #include "parser/parse_type.h"
+#include "parser/scansup.h"
 #include "tcop/tcopprot.h"
 #include "utils/acl.h"
 #include "utils/array.h"
@@ -2257,13 +2258,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);
 
@@ -2289,13 +2290,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);
 
@@ -2313,14 +2314,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);