pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Jorge Gustavo Rocha <jgr@geomaster.pt>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15827: Unable to connect on Windows using pg_services.conf using Python psycopg2
Date: Thu, 20 Jun 2019 16:03:19 +0900
Message-ID: <20190620070319.GH2660@paquier.xyz> (raw)
In-Reply-To: <20190620031218.GC2660@paquier.xyz>
References: <15827-e6ba53a3a7ed543c@postgresql.org>
	<82491.1559409563@sss.pgh.pa.us>
	<e12a23c6-5e00-3fa6-6179-681336130361@geomaster.pt>
	<1473.1560866085@sss.pgh.pa.us>
	<fcb5c34c-cf5f-6dc9-c68e-6b297f073b79@geomaster.pt>
	<CA+mi_8aBnLKypX2Ttksg8JEhApBo=JpF6P_STQGp-FOvDpn6Yw@mail.gmail.com>
	<81d9d421-6947-7111-a1dc-cfd99cd3ae53@geomaster.pt>
	<23215.1560977098@sss.pgh.pa.us>
	<20190620031218.GC2660@paquier.xyz>

On Thu, Jun 20, 2019 at 12:12:18PM +0900, Michael Paquier wrote:
> The discussion here is on 10, and the password file has does not
> enforce the flag either because it filters '\r' by itself.  So another
> solution may be to do the same thing as what's done in
> passwordFromFile()?

That still sounds like a good idea to do at the end.  So attached is
the Dr Evil's version I was thinking of, and that would be rather
back-patchable.  (Spoiler: not seriously tested.)

Thoughts?
--
Michael

Attachments:

  [text/x-diff] service-libpq-crlf-v1.patch (1.1K, ../20190620070319.GH2660@paquier.xyz/2-service-libpq-crlf-v1.patch)
  download | inline diff:
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index c800d7921e..4e6902daef 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -5020,6 +5020,8 @@ parseServiceFile(const char *serviceFile,
 
 	while ((line = fgets(buf, sizeof(buf), f)) != NULL)
 	{
+		int			len;
+
 		linenr++;
 
 		if (strlen(line) >= sizeof(buf) - 1)
@@ -5032,16 +5034,23 @@ parseServiceFile(const char *serviceFile,
 			return 2;
 		}
 
+		len = strlen(line);
+
 		/* ignore EOL at end of line */
-		if (strlen(line) && line[strlen(line) - 1] == '\n')
-			line[strlen(line) - 1] = 0;
+		if (len > 0 && line[len - 1] == '\n')
+		{
+			line[--len] = '\0';
+			/* Handle DOS-style line endings, too, even when not on Windows */
+			if (len > 0 && line[len - 1] == '\r')
+				line[--len] = '\0';
+		}
 
 		/* ignore leading blanks */
 		while (*line && isspace((unsigned char) line[0]))
 			line++;
 
 		/* ignore comments and empty lines */
-		if (strlen(line) == 0 || line[0] == '#')
+		if (len == 0 || line[0] == '#')
 			continue;
 
 		/* Check for right groupname */

  [application/pgp-signature] signature.asc (832B, ../20190620070319.GH2660@paquier.xyz/3-signature.asc)
  download

view thread (23+ messages)  latest in thread

Message-ID: <20190620070319.GH2660@paquier.xyz>
Permalink:  ../20190620070319.GH2660@paquier.xyz/
Also on:    postgresql.org/message-id/20190620070319.GH2660@paquier.xyz

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: michael@paquier.xyz, tgl@sss.pgh.pa.us, jgr@geomaster.pt, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #15827: Unable to connect on Windows using pg_services.conf using Python psycopg2
  In-Reply-To: <20190620070319.GH2660@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox