Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oNcPn-0008Me-V6 for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Aug 2022 15:54:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oNcPm-0004rG-JU for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Aug 2022 15:54:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oNcPm-0004r7-BB for pgsql-bugs@lists.postgresql.org; Mon, 15 Aug 2022 15:54:06 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oNcPk-0008MM-2e for pgsql-bugs@postgresql.org; Mon, 15 Aug 2022 15:54:05 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 27FFs1QW920912; Mon, 15 Aug 2022 11:54:01 -0400 From: Tom Lane To: Daniele Varrazzo cc: Francisco Olarte , pgsql-bugs Subject: Re: [PATCH] Fix segfault calling PQflush on invalid connection In-reply-to: References: <819197.1660527847@sss.pgh.pa.us> Comments: In-reply-to Daniele Varrazzo message dated "Mon, 15 Aug 2022 16:57:58 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <920910.1660578841.1@sss.pgh.pa.us> Date: Mon, 15 Aug 2022 11:54:01 -0400 Message-ID: <920911.1660578841@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Daniele Varrazzo writes: > After exercising most of the libpq API in psycopg 3, PQflush() seems > the only one requiring a guard [1]. All the other functions seem to > behave well when passed an "invalid connection" - aka either a NULL > pointer or a connection in BAD status. I went so far as to inspect every function listed in libpq/exports.txt. All the ones that take a PGconn or PGresult check it for NULL except PQflush PQisnonblocking PQdefaultSSLKeyPassHook_OpenSSL PQisnonblocking is clearly an oversight, same as PQflush. Maybe there is a case for not bothering to check in PQdefaultSSLKeyPassHook_OpenSSL, on the grounds that you'd not get that far without a connection, but I think for consistency it should do so too. There is not a lot of consistency about whether we insist on the connection being in any particular "good" state. For some of the functions I think it's intentional that they should still work on a failed connection, but I wonder if any of those are likewise oversights. regards, tom lane