aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorItagaki Takahiro <itagaki.takahiro@gmail.com>2010-06-03 09:40:17 +0000
committerItagaki Takahiro <itagaki.takahiro@gmail.com>2010-06-03 09:40:17 +0000
commit442d94142ce20a36e277ad1abbfb2891bd2c5477 (patch)
treeadad3468721f9ddabf9f23919b549c36cd7b4e2b
parent619360f59bd3722bd2e4491d6103237c00e4b723 (diff)
downloadpostgresql-442d94142ce20a36e277ad1abbfb2891bd2c5477.tar.gz
postgresql-442d94142ce20a36e277ad1abbfb2891bd2c5477.zip
Fix dblink to treat connection names longer than NAMEDATALEN-2 (62 bytes).
Now long names are adjusted with truncate_identifier() and NOTICE messages are raised if names are actually truncated. Backported to release 8.0.
-rw-r--r--contrib/dblink/dblink.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 4869d95facc..cde6c329570 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -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.82.2.2 2010/02/03 23:01:23 joe Exp $
+ * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.82.2.3 2010/06/03 09:40:17 itagaki Exp $
* Copyright (c) 2001-2009, 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"
@@ -2231,13 +2232,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);
@@ -2263,13 +2264,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);
@@ -2287,14 +2288,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);
@@ -2428,10 +2428,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)
{