8000 Fix dblink to treat connection names longer than NAMEDATALEN-2 (62 by… · danielcode/postgres@ac14ba5 · GitHub
[go: up one dir, main page]

Skip to content

Commit ac14ba5

Browse files
committed
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.
1 parent dbfa55f commit ac14ba5

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

contrib/dblink/dblink.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "nodes/execnodes.h"
4848
#include "nodes/pg_list.h"
4949
#include "parser/parse_type.h"
50+
#include "parser/scansup.h"
5051
#include "tcop/tcopprot.h"
5152
#include "utils/builtins.h"
5253
#include "utils/fmgroids.h"
@@ -2107,13 +2108,13 @@ static remoteConn *
21072108
getConnectionByName(const char *name)
21082109
{
21092110
remoteConnHashEnt *hentry;
2110-
char key[NAMEDATALEN];
2111+
char *key;
21112112

21122113
if (!remoteConnHash)
21132114
remoteConnHash = createConnHash();
21142115

2115-
MemSet(key, 0, NAMEDATALEN);
2116-
snprintf(key, NAMEDATALEN - 1, "%s", name);
2116+
key = pstrdup(name);
2117+
truncate_identifier(key, strlen(key), true);
21172118
hentry = (remoteConnHashEnt *) hash_search(remoteConnHash,
21182119
key, HASH_FIND, NULL);
21192120

@@ -2139,13 +2140,13 @@ createNewConnection(const char *name, remoteConn * rconn)
21392140
{
21402141
remoteConnHashEnt *hentry;
21412142
bool found;
2142-
char key[NAMEDATALEN];
2143+
char *key;
21432144

21442145
if (!remoteConnHash)
21452146
remoteConnHash = createConnHash();
21462147

2147-
MemSet(key, 0, NAMEDATALEN);
2148-
snprintf(key, NAMEDATALEN - 1, "%s", name);
2148+
key = pstrdup(name);
2149+
truncate_identifier(key, strlen(key), true);
21492150
hentry = (remoteConnHashEnt *) hash_search(remoteConnHash, key,
21502151
HASH_ENTER, &found);
21512152

@@ -2163,14 +2164,13 @@ deleteConnection(const char *name)
21632164
{
21642165
remoteConnHashEnt *hentry;
21652166
bool found;
2166-
char key[NAMEDATALEN];
2167+
char *key;
21672168

21682169
if (!remoteConnHash)
21692170
remoteConnHash = createConnHash();
21702171

2171-
MemSet(key, 0, NAMEDATALEN);
2172-
snprintf(key, NAMEDATALEN - 1, "%s", name);
2173-
2172+
key = pstrdup(name);
2173+
truncate_identifier(key, strlen(key), true);
21742174
hentry = (remoteConnHashEnt *) hash_search(remoteConnHash,
21752175
key, HASH_REMOVE, &found);
21762176

0 commit comments

Comments
 (0)
0