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

Skip to content

Commit 9d1f441

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 de57ea1 commit 9d1f441

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
@@ -48,6 +48,7 @@
4848
#include "nodes/execnodes.h"
4949
#include "nodes/pg_list.h"
5050
#include "parser/parse_type.h"
51+
#include "parser/scansup.h"
5152
#include "tcop/tcopprot.h"
5253
#include "utils/builtins.h"
5354
#include "utils/fmgroids.h"
@@ -2075,13 +2076,13 @@ static remoteConn *
20752076
getConnectionByName(const char *name)
20762077
{
20772078
remoteConnHashEnt *hentry;
2078-
char key[NAMEDATALEN];
2079+
char *key;
20792080

20802081
if (!remoteConnHash)
20812082
remoteConnHash = createConnHash();
20822083

2083-
MemSet(key, 0, NAMEDATALEN);
2084-
snprintf(key, NAMEDATALEN - 1, "%s", name);
2084+
key = pstrdup(name);
2085+
truncate_identifier(key, strlen(key), true);
20852086
hentry = (remoteConnHashEnt *) hash_search(remoteConnHash,
20862087
key, HASH_FIND, NULL);
20872088

@@ -2107,13 +2108,13 @@ createNewConnection(const char *name, remoteConn * con)
21072108
{
21082109
remoteConnHashEnt *hentry;
21092110
bool found;
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, key,
21182119
HASH_ENTER, &found);
21192120

@@ -2136,14 +2137,13 @@ deleteConnection(const char *name)
21362137
{
21372138
remoteConnHashEnt *hentry;
21382139
bool found;
2139-
char key[NAMEDATALEN];
2140+
char *key;
21402141

21412142
if (!remoteConnHash)
21422143
remoteConnHash = createConnHash();
21432144

2144-
MemSet(key, 0, NAMEDATALEN);
2145-
snprintf(key, NAMEDATALEN - 1, "%s", name);
2146-
2145+
key = pstrdup(name);
2146+
truncate_identifier(key, strlen(key), true);
21472147
hentry = (remoteConnHashEnt *) hash_search(remoteConnHash,
21482148
key, HASH_REMOVE, &found);
21492149

0 commit comments

Comments
 (0)
0