Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdr6Y-0004Ug-Lj for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Jun 2019 07:03:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hdr6W-00040z-Pa for pgsql-bugs@arkaria.postgresql.org; Thu, 20 Jun 2019 07:03:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdr6W-00040b-Ee for pgsql-bugs@lists.postgresql.org; Thu, 20 Jun 2019 07:03:28 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdr6U-0006vE-7Z for pgsql-bugs@lists.postgresql.org; Thu, 20 Jun 2019 07:03:27 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id F356B222D5; Thu, 20 Jun 2019 03:03:24 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 20 Jun 2019 03:03:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm2; bh=f/hznGR/JfDu0aLfQ8ZPKvmHsns k5ujb632yOBYEkLs=; b=HiOkG5ws7BcWGwLD3itTbw+Y43xSAaNO0LMvFMbu2Zk +Q0q/2kVhmXHOpBoC3FIotvikVdN6Nc4Bax67+l8ejv2tgSo4vnWCjSU/wIejqft lJFTwsprOEx4/yRDy8jterKTqjRN+JXAfvxk/m9SQWj1yBrYKHRdBu49cafX7Ioc VU4SegyxkHWTxOCGQgZViE9OYdlUpObWebIIGpQqPv6acwNDvpnsr1HcH9x4b5j4 DyhzjJbZAnDqHJBbo8Co9BeIjKJEXs4kHttw9pLsJkJTxfWzHglbzTPexzet67h5 2x8+EYjZJdDUHc6h6SBszgwusDrGCKKirsrjj6w5+QA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=f/hznG R/JfDu0aLfQ8ZPKvmHsnsk5ujb632yOBYEkLs=; b=xufnS8Hkrhl9jiH4BZZTt0 n62B1RPHzaai8nduOdDpXgMezd0jAvOsbcryayEday4CTYtU3RMqvaHrh1mYxF5H tvIomdKfeRVI8yEdllfcdw0VVwiKbNsp6WIvlYP4le5qSiv3vhAHRCgmke3Vd1NS mIYuqYCqTSyzJzTjVzv0L0O3yRz8TpgWK/HB5hIGB0GzsdXHjrXIgz4TkmffwhTk Sm00cgjffHULSLxqLDGnbY0lL2CgV/4gXHTUwPdH8UQy4tnmHFQCeBvMrbEa33nG Dv8lwY5vyNJYaux3gY5Ba4cHC96XlD2JyH4/919yMo6K3o0gRcvYOhrlIryuQpWA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrtdefgdduudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpeffhf fvuffkfhggtggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhu ihgvrhcuoehmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucfkphepudduuddrud dtvddrudektddrudekheenucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhes phgrqhhuihgvrhdrgiihiienucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id DF712380074; Thu, 20 Jun 2019 03:03:22 -0400 (EDT) Date: Thu, 20 Jun 2019 16:03:19 +0900 From: Michael Paquier To: Tom Lane Cc: Jorge Gustavo Rocha , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15827: Unable to connect on Windows using pg_services.conf using Python psycopg2 Message-ID: <20190620070319.GH2660@paquier.xyz> References: <15827-e6ba53a3a7ed543c@postgresql.org> <82491.1559409563@sss.pgh.pa.us> <1473.1560866085@sss.pgh.pa.us> <81d9d421-6947-7111-a1dc-cfd99cd3ae53@geomaster.pt> <23215.1560977098@sss.pgh.pa.us> <20190620031218.GC2660@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="T4IYkFBVPN84tP7K" Content-Disposition: inline In-Reply-To: <20190620031218.GC2660@paquier.xyz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --T4IYkFBVPN84tP7K Content-Type: multipart/mixed; boundary="YhFoJY/gx7awiIuK" Content-Disposition: inline --YhFoJY/gx7awiIuK Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --YhFoJY/gx7awiIuK Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="service-libpq-crlf-v1.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-co= nnect.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, =20 while ((line =3D fgets(buf, sizeof(buf), f)) !=3D NULL) { + int len; + linenr++; =20 if (strlen(line) >=3D sizeof(buf) - 1) @@ -5032,16 +5034,23 @@ parseServiceFile(const char *serviceFile, return 2; } =20 + len =3D strlen(line); + /* ignore EOL at end of line */ - if (strlen(line) && line[strlen(line) - 1] =3D=3D '\n') - line[strlen(line) - 1] =3D 0; + if (len > 0 && line[len - 1] =3D=3D '\n') + { + line[--len] =3D '\0'; + /* Handle DOS-style line endings, too, even when not on Windows */ + if (len > 0 && line[len - 1] =3D=3D '\r') + line[--len] =3D '\0'; + } =20 /* ignore leading blanks */ while (*line && isspace((unsigned char) line[0])) line++; =20 /* ignore comments and empty lines */ - if (strlen(line) =3D=3D 0 || line[0] =3D=3D '#') + if (len =3D=3D 0 || line[0] =3D=3D '#') continue; =20 /* Check for right groupname */ --YhFoJY/gx7awiIuK-- --T4IYkFBVPN84tP7K Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAl0LL7cACgkQnvQgOdby QH2hmQ//Q4bEuLYA6IhTn6GkUWGkn7gLEL00bKRLu/6hyVyHpLObasum7uSlx3lO XTRjOezx3vWZgnbp/7Qs/4ZOUCbdyJAtOcGZjz06SG6rO1Z3wMqNlx1GNvbCcDNi RD78BsooyiwYgJGBKc17FM20g1/iZsxCMlnPqS+6jJ48nq3sQPFRLz2mSFY/Gfbf tikC1cXvqEr9wQivQEZTI/TU0S40VpqlhvIvnra39suaqqrqyLIXbPIYgw61c1/c afJgZigzq+VgFeTU7M1DuaznDBeiZvSykPdLreodl3nlcSWuQg9IACDBg6qUrxvF 7aJ+YjuHwbkoUjUE+a+WhvoujiuZY+/TBF5sSSAJSDIO0jd3ZER0gzhJl+ajmzhF eHvowb5l9l7sRAude9QpAVe/0Wgy3JZ0t3Nz+95v8CnNkI5KW3zHj44bA/Q3rOSu xBINRktEBoBEnUEn0gK+tM7EUYVfFJkRHTWL5zyM3G5h5JuSsnzTJqIMIk2apLvK MZIcKCM1Z+/GO9OcQKQrYVicFdOjFbL6zm9R8RT8axRgcb36mnY1AzmQ+St3To9C 4yoL2v+YYV0A5cSKcHrpyXkxxGHz/KtulYxlnBQ0UMh18QzWm4M5rNs3cmPlbR0B tMvzDnwxIDVPxhfqGUU3jdOCfMuPy7RNxeM5Qoa2IF8aIhlsLvU= =yfQU -----END PGP SIGNATURE----- --T4IYkFBVPN84tP7K--