Fix dblink to treat connection names longer than NAMEDATALEN-2 (62 bytes).
authorItagaki Takahiro <[email protected]>
Thu, 3 Jun 2010 09:43:04 +0000 (09:43 +0000)
committerItagaki Takahiro <[email protected]>
Thu, 3 Jun 2010 09:43:04 +0000 (09:43 +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 d46c2c5174638381be1338b4ad10f401589ead91..bbe40060a2f3e61e70ad31aae0e4d67d67690dfd 100644 (file)
@@ -8,7 +8,7 @@
  * Darko Prenosil <[email protected]>
  * Shridhar Daithankar <[email protected]>
  *
- * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.60.2.5 2010/02/03 23:01:47 joe Exp $
+ * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.60.2.6 2010/06/03 09:43:04 itagaki Exp $
  * Copyright (c) 2001-2006, PostgreSQL Global Development Group
  * ALL RIGHTS RESERVED;
  *
@@ -50,6 +50,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/array.h"
 #include "utils/builtins.h"
@@ -2243,13 +2244,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);
 
@@ -2275,13 +2276,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);
 
@@ -2299,14 +2300,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);