pgsql: Fix dblink to treat connection names longer than NAMEDATALEN-2

Lists: pgsql-committerspgsql-hackers
From: itagaki(at)postgresql(dot)org (Takahiro Itagaki)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix dblink to treat connection names longer than NAMEDATALEN-2
Date: 2010-06-03 09:38:33
Message-ID: 20100603093833.B8B687541D2@cvs.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Log Message:
-----------
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.

Modified Files:
--------------
pgsql/contrib/dblink:
dblink.c (r1.91 -> r1.92)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/contrib/dblink/dblink.c?r1=1.91&r2=1.92)


From: Takahiro Itagaki <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [COMMITTERS] pgsql: Fix dblink to treat connection names longer than NAMEDATALEN-2
Date: 2010-06-08 06:17:20
Message-ID: 20100608151720.3606.52131E4D@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers


itagaki(at)postgresql(dot)org (Takahiro Itagaki) wrote:

> 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.
>
> Modified Files:
> --------------
> pgsql/contrib/dblink:
> dblink.c (r1.91 -> r1.92)
> (http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/contrib/dblink/dblink.c?r1=1.91&r2=1.92)

I had a mistake in the fix below. get_connect_string() is called
not only in the case of server-based connections, but also in
connection-string-based connections. If connection strings longer
than 63 bytes are passed the routine emits "identifier will be truncated"
warning. It is an incompatbile change.

Should we revert the change, or just adjust to call truncate_identifier
with warn=false ?

*************** get_connect_string(const char *servernam
*** 2390,2399 ****
StringInfo buf = makeStringInfo();
ForeignDataWrapper *fdw;
AclResult aclresult;

/* first gather the server connstr options */
! if (strlen(servername) < NAMEDATALEN)
! foreign_server = GetForeignServerByName(servername, true);

if (foreign_server)
{
--- 2390,2401 ----
StringInfo buf = makeStringInfo();
ForeignDataWrapper *fdw;
AclResult aclresult;
+ char *srvname;

/* first gather the server connstr options */
! srvname = pstrdup(servername);
! truncate_identifier(srvname, strlen(srvname), true);
! foreign_server = GetForeignServerByName(srvname, true);

if (foreign_server)
{

Regards,
---
Takahiro Itagaki
NTT Open Source Software Center