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 1hdEZa-0005WP-BF for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Jun 2019 13:54:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hdEZZ-0007Tp-1y for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Jun 2019 13:54:53 +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 1hdEZY-0007Sg-MK for pgsql-bugs@lists.postgresql.org; Tue, 18 Jun 2019 13:54:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdEZW-0003iT-DO for pgsql-bugs@lists.postgresql.org; Tue, 18 Jun 2019 13:54:51 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x5IDsjRQ001474; Tue, 18 Jun 2019 09:54:46 -0400 From: Tom Lane To: Jorge Gustavo Rocha cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15827: Unable to connect on Windows using pg_services.conf using Python psycopg2 In-reply-to: References: <15827-e6ba53a3a7ed543c@postgresql.org> <82491.1559409563@sss.pgh.pa.us> Comments: In-reply-to Jorge Gustavo Rocha message dated "Tue, 18 Jun 2019 14:13:01 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1472.1560866085.1@sss.pgh.pa.us> Date: Tue, 18 Jun 2019 09:54:45 -0400 Message-ID: <1473.1560866085@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jorge Gustavo Rocha writes: > 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. So it would seem. > 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. Well, that's exactly the question at issue: doesn't Windows' fgets() convert \r\n to just \n? I should think that it generally does, because we have a *lot* of fgets() calls and a quick scan says that the majority of them aren't taking care to get rid of \r. If you can convince me that this is actually a behavior seen in the wild, we're going to need to change way more places than just this one. Googling for this didn't provide a lot of insight, although I did find one person speculating that if you used GNU glibc on Windows it would not strip \r. That seems unlikely though. Another possibility is that you're on a Unix machine but you're wishing libpq would deal with a service file that has Windows-style newlines. Anyway, I want some clarity about what's really happening here, because I'm disinclined to touch several dozen call sites on the basis of speculation. > I've saw many people complaining of this tiny issue and I think it is > easy to solve. Nobody else has complained of this that I've heard of. Please let's deal in verifiable facts. regards, tom lane