From 3ba0ef7fc6565bdcd3dfbd3a00aab9ca3c2122f7 Mon Sep 17 00:00:00 2001 From: Itagaki Takahiro Date: Thu, 3 Jun 2010 09:41:26 +0000 Subject: [PATCH] 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. --- contrib/dblink/dblink.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index 1360c7a00dc..5f5e652cfcc 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -8,7 +8,7 @@ * Darko Prenosil * Shridhar Daithankar * - * $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);