Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wN1BK-000W8S-0l for pgsql-hackers@arkaria.postgresql.org; Wed, 13 May 2026 04:26:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wN1BI-0079Nu-1j for pgsql-hackers@arkaria.postgresql.org; Wed, 13 May 2026 04:26:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wN1BH-0079Nl-1o for pgsql-hackers@lists.postgresql.org; Wed, 13 May 2026 04:26:48 +0000 Received: from fhigh-b3-smtp.messagingengine.com ([202.12.124.154]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wN1BD-00000000JRI-3Byv for pgsql-hackers@lists.postgresql.org; Wed, 13 May 2026 04:26:45 +0000 Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.stl.internal (Postfix) with ESMTP id D41497A0148; Wed, 13 May 2026 00:26:42 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Wed, 13 May 2026 00:26:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1778646402; x=1778732802; bh=3PJtrJTfyJ d87YZfsLWwkHkDKrLmlKeCcCBaiI6CO7Y=; b=lesPOH4UGFAo5BJeFJtnCb0D3h dOsh5jYmv9HtWJQWWnaBG3EKvzrXE0lqxjxVJB0RVteWSZaUNzFdJto4B86PwTRG m/huguAXRuNuYxQXJO/cfeSzXAwnscsdYzq2nzHC2g6km8Co1K8ZAu7He5kQplki w8BxzXq+CYL7zvtQjwoOuuWM2DNHUIm6Q+nYUL3RdjDN3LVIgqQmCz8+w4SAUIgh G59y0ZP3i2MONYaJCAlW/f67A/zbfnrcZMt9JqPNU4VFjEtMJhGSSlbsW0vD60Cp 1DeYCxyn2WWVhbQtexCbQAhqifzBTeVL5TVL9iZDuufYT0cHKcOZJSqIExUw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1778646402; x=1778732802; bh=3PJtrJTfyJd87YZfsLWwkHkDKrLmlKeCcCB aiI6CO7Y=; b=PSpVUrn2/QnwvyiCFhfV6y9NrQYkDO6M2pkD90tGv4zqg1EV0a7 LhydSn2kj9x2gJh+SiJDU99JXWzO8JOxdZx9qQAghRZrTi5CxIyTAv002TP7/Xvh jn2YNAqgu+uLryqBaTPOCxAPuUezB0vE6UVk5zVGUkOURqaltX+a6iagKuhampAQ tRo5+i7tqYOhq9GdBp70xNCpymdKW2WT9+gc7fysrezSE+rHvGAv+1gw4r4GkT0K hYrzxAE7FZypVTWb3OGV3e0jSfrehllWlSLLayrCUETq2+49Yh1CnSBMXdfnpbZF vANwi0CsXzN7R0lGJaRWWtIkezJe7dIu56w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdduvdefjedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrh hlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeggeeg fffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiidp nhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheprghnug hrvghssegrnhgrrhgriigvlhdruggvpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghr sheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtoheplhhirdgvvh grnhdrtghhrghosehgmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 13 May 2026 00:26:40 -0400 (EDT) Date: Wed, 13 May 2026 13:26:36 +0900 From: Michael Paquier To: Andres Freund Cc: pgsql-hackers@lists.postgresql.org, Chao Li Subject: Re: Fix unsafe PlannedStmt access in pg_stat_statements Message-ID: References: <2F91906A-F2B5-4A6B-9695-D136957D4545@gmail.com> <0A9A8DAC-BC3C-4C7A-9504-2C6050405544@anarazel.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="aQV8ndjkSAbor7fN" Content-Disposition: inline In-Reply-To: <0A9A8DAC-BC3C-4C7A-9504-2C6050405544@anarazel.de> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --aQV8ndjkSAbor7fN Content-Type: multipart/mixed; boundary="aS+OdXZcn57JmTmF" Content-Disposition: inline --aS+OdXZcn57JmTmF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, May 12, 2026 at 11:00:16AM +0200, Andres Freund wrote: > Seems like the code should make this clearer, by simply unsetting > pstmt at the point it becomes unsafe to use?=20 Sure, we could do that as well and crash hard if something decides to do the same mistake. Like the simple patch attached for example? I am not sure if we need to update the comment. It's pretty clear what the intention is, at least to me. -- Michael --aS+OdXZcn57JmTmF Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=pgss-pstmt.patch Content-Transfer-Encoding: quoted-printable diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_s= tat_statements/pg_stat_statements.c index a2d3ab770cc6..92315627916d 100644 --- a/contrib/pg_stat_statements/pg_stat_statements.c +++ b/contrib/pg_stat_statements/pg_stat_statements.c @@ -1175,6 +1175,7 @@ pgss_ProcessUtility(PlannedStmt *pstmt, const char *q= ueryString, * For the same reason, we can't risk restoring pstmt->queryId to its * former value, which'd otherwise be a good idea. */ + pstmt =3D NULL; =20 INSTR_TIME_SET_CURRENT(duration); INSTR_TIME_SUBTRACT(duration, start); --aS+OdXZcn57JmTmF-- --aQV8ndjkSAbor7fN Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmoD/XwACgkQnvQgOdby QH1q2w/9HTqwUVxJw5wgXtGVnYQi/c5Y8dlzwMmt5EQFW/sQCA4bAy8iGxWLMIw2 fSuCln9xZ2/4XDJtVvi21QhQ1Y/ChH4J5Yz42X9jIqG73R1P/DxG8KqdjfGzuGcJ qXKMYczpZ3L+KeyBdPIyaxbF83JgsNvvoUWUuGXWMukFebPEStnI3AV6w//kL4gd CdOWOngi5KxgDX67ZD5p54mZRLYnSalLUBaNqduww+QdVPnFSMeRjMK4LhkTeYWN HPkZhSQ+5aLRQq2rtzEoI0QdCZ8bSq2bTMoPHcWLYRF428T5mQVERGZZu5GHWkYd AVdV9JVyk1AUyvDkY3xb2yOmxEF4HaB8eXXxlFis9OTuwkHEk/j5KZSg7xsluIpt 6TSUIyYW/Wx7oblpEBeHdmdu9V5/BdOcmvLaS578Mn3nW2lTPGwrCh+tPRYAEJgE iVi66Mf3Pdrz/ajQAxuGTceoLUHotS1yKYEkA4Ys8bMSlLOz2GPBQmre9uBUmFJf OHneODpROphuHF95IDKBzbXACe4GEPdkBS7NnHERBwMLdrPXqG6sGi9lLMECFER/ CKZttjZAvYdNBrJ1wdwHFBdQ3ZQFsgQArJJVq7FFJO7+m0jFwWoc1wHQvbA3LC5Z vWMumkXsmgo4sEPl19g20kaBvAK6yC7Mf9sY95GlRbulIMiPgT4= =V42J -----END PGP SIGNATURE----- --aQV8ndjkSAbor7fN--