Re: BUG #15827: Unable to connect on Windows using pg_services.conf using Python psycopg2

From: Jorge Gustavo Rocha <jgr(at)geomaster(dot)pt>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #15827: Unable to connect on Windows using pg_services.conf using Python psycopg2
Date: 2019-06-18 13:13:01
Message-ID: e12a23c6-5e00-3fa6-6179-681336130361@geomaster.pt
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Dear Tom Lane,

Thank you for your feedback.

The '\r' on pg_services.conf is causing problems on Windows. The
parseServiceFile function returns the host or hostaddr with a trialing
'\r'. Subsequent attempts to turn that into an address will fail.

I've checked the code, and parseServiceFile uses the standard C fgets
library function. Since fgets copies all characters until '\n'
(including the '\n'), the resulting line (right now) preserves the '\r'
at the end, on Windows.

Since parseServiceFile already checks for the trailing '\n' and removes
it, I think we can also check for a trailing '\r' and remove it. So, I
suggest to improve the parseServiceFile function [1] to discard trailing
'\r'.

I've isolated the problem, and I think the attached patch solves this
issue. The added filter for '\r' has no effect if the pg_services file
does not have any '\r'.

I've saw many people complaining of this tiny issue and I think it is
easy to solve.

What do you think? Do you see any inconvenient in filtering '\r'?

Best regards,

Gustavo

[1] src/interfaces/libpq/fe-connect.c

Às 18:19 de 01/06/19, Tom Lane escreveu:
> PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
>> I'm using `pg_services.conf` to provide access to a Postgresql database.
>> ...
>> From other's feedback, I've tried to use the line separators in
>> pg_services.conf with \n and \r\n, but the result is the same (because there
>> is strange newline after the host address).
> Hm, can you double check that? It sure looks like something is failing to
> remove the "\r" from that line of pg_service.conf. Which is odd, because
> libpq opens the file in text mode so the Windows C library ought to take
> care of reducing "\r\n" to "\n".
>
> It seems like in general, maybe we ought to trim trailing spaces from
> pg_service.conf entries automatically. But I'm not entirely sure if
> that would fix this problem...
>
> regards, tom lane
>
>
--
Logo*   Geomaster, LDA*
  *VENHA DESCOBRIR O CAMINHO DO OPEN SOURCE CONNOSC**O

*
 
Avenida Barros e Soares
N.º 423, 4715-214 Braga
VAT/NIF510 906 109
Phone  +351 253 680 323
Site       geomaster.pt <http://geomaster.pt>
GPS       41.53322, -8.41929

------------------------------------------------------------------------
 
Jorge Gustavo Rocha
CTO

Mobile  +351 910 333 888
Email    jgr(at)geomaster(dot)pt

Attachment Content-Type Size
parseServiceFile.patch text/x-patch 572 bytes

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2019-06-18 13:17:02 Re: BUG #15857: Parallel Hash Join makes join instead of exists
Previous Message Jeff Janes 2019-06-18 12:22:14 Re: Querying foreign table with SP-GiST index results in “ERROR: cache lookup failed for type 0”