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 1oNP9K-0006tB-FG for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Aug 2022 01:44:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oNP9I-0000Wu-Qe for pgsql-bugs@arkaria.postgresql.org; Mon, 15 Aug 2022 01:44:12 +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 1oNP9I-0000Wl-Hh for pgsql-bugs@lists.postgresql.org; Mon, 15 Aug 2022 01:44:12 +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 1oNP9G-0001IZ-8K for pgsql-bugs@postgresql.org; Mon, 15 Aug 2022 01:44:11 +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 27F1i71A819198; Sun, 14 Aug 2022 21:44:07 -0400 From: Tom Lane To: Daniele Varrazzo cc: pgsql-bugs Subject: Re: [PATCH] Fix segfault calling PQflush on invalid connection In-reply-to: References: Comments: In-reply-to Daniele Varrazzo message dated "Mon, 15 Aug 2022 02:44:55 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <819196.1660527847.1@sss.pgh.pa.us> Date: Sun, 14 Aug 2022 21:44:07 -0400 Message-ID: <819197.1660527847@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Daniele Varrazzo writes: > PQflush calls pqFlush, which performs struct access to the connection > without checking if it's valid, resulting in a segfault if called with > a null pointer. > Please find attached a patch adding a guard to PQflush(). Seems reasonable, but this tickled a thought that's been in my hindbrain for awhile: just checking for a null pointer is not much of a check for being passed a valid PGconn pointer. Should we add a magic number to struct PGconn, and modify all libpq's entry points along the lines of if (!conn || conn->magic != PGCONN_MAGIC) return failure; I'm honestly not entirely sure if this is worth the trouble; I've not heard of many application bugs that this would've caught. But the lack of any such check does seem like it's not up to modern standards. regards, tom lane