Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jIwS4-0004e7-5o for pgsql-bugs@arkaria.postgresql.org; Mon, 30 Mar 2020 15:35:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jIwS2-0000V6-ES for pgsql-bugs@arkaria.postgresql.org; Mon, 30 Mar 2020 15:35:46 +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 1jIwS2-0000Uy-8U for pgsql-bugs@lists.postgresql.org; Mon, 30 Mar 2020 15:35:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jIwS0-0006t2-1q for pgsql-bugs@lists.postgresql.org; Mon, 30 Mar 2020 15:35:45 +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 02UFZfiA017010; Mon, 30 Mar 2020 11:35:41 -0400 From: Tom Lane To: Michael Paquier cc: hghwng@gmail.com, pgsql-bugs@lists.postgresql.org, Alvaro Herrera Subject: Re: BUG #16330: psql accesses null pointer in connect.c:do_connect In-reply-to: <20200330071937.GC43995@paquier.xyz> References: <16330-b34835d83619e25d@postgresql.org> <20200330071937.GC43995@paquier.xyz> Comments: In-reply-to Michael Paquier message dated "Mon, 30 Mar 2020 16:19:37 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <17008.1585582541.1@sss.pgh.pa.us> Date: Mon, 30 Mar 2020 11:35:41 -0400 Message-ID: <17009.1585582541@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Michael Paquier writes: > On Mon, Mar 30, 2020 at 02:20:48AM +0000, PG Bug reporting form wrote: >> If the connection to postmaster is closed, then trying to re-connect to >> another one leads to SIGSEGV. > A fix like the attached should be sufficient as if we know that > PQhost() is NULL for the old connection we cannot use the old > hostaddr. Alvaro, what do you think? It looks to me like there's a similar hazard a bit further down (line 3029): appendConnStrVal(&connstr, PQdb(o_conn)); I wonder if we should force reuse_previous to false if there's no o_conn, rather than fixing this stuff piecemeal. regards, tom lane