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.94.2) (envelope-from ) id 1rfajF-00149J-3r for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Feb 2024 07:21:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rfajD-000pcJ-Dv for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Feb 2024 07:21:15 +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.94.2) (envelope-from ) id 1rfajB-000pcB-Jk for pgsql-hackers@lists.postgresql.org; Thu, 29 Feb 2024 07:21:15 +0000 Received: from fhigh8-smtp.messagingengine.com ([103.168.172.159]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rfaj7-00242z-J6 for pgsql-hackers@lists.postgresql.org; Thu, 29 Feb 2024 07:21:12 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id CC1F7114015F for ; Thu, 29 Feb 2024 02:21:09 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 29 Feb 2024 02:21:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:content-type:content-type:date:date:from:from:in-reply-to :message-id:mime-version:reply-to:subject:subject:to:to; s=fm1; t=1709191269; x=1709277669; bh=bGxD1aTbZG57GizY4fC0zUk1zPhzSky6 OY8uoxD0qbA=; b=gl2mYtzqZwwmS4TcCaxkX9u1KpDxRFZP9XOiAhlJL9rgzqW0 TqGr36t7Hrmy55MVtlsZ/Gn8FD07TETPwnxlEiv3BM8/t15sDv0XmBCHd3BnPMQA JsieVWaJs89S/pHls09wOygVdk/l7FIvNsU2+jDuQzqYTILgLV66y23mAVVb2BzH 8ooIRUvUdYVK1BdJ+5iMiwXN0QmQ8xOEfStwwfPa2jY8lLOSb1EwhGI4TCl9SMmM iy8K7Moz8NJRedekXMkFqgSBJcujYWH9kXpp8e5Z/wAbkxcdXE3WhiR4PlOd0Lab 78CHkVd2C3KTR92wi0C1cEM5L07DUT3tZmwsLw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1709191269; x=1709277669; bh=bGxD1aTbZG57GizY4fC0zUk1zPhzSky6OY8 uoxD0qbA=; b=Irtz5lbFm28tlg0s1nTFCqaCRDQLsSv8ABhw4vu0EI7r+ObDGrd rr2Mj75smETRxQMBlk6soq04HVGSfp9wzP+pwuNlZOYvCGmvhuor1wj/Aan4Gb87 rne75uHOUXWE2wNIfgs3iRJ30g/wP+YIQ8aSc5RSzfueTlBL9yhZQ8vSwN6Fkv3c N9N2mcooMrXYuEPod5roJnToG2LbaUEma8P8K1Av+SJFCeMblrTE1ij/zAboTpcU gJN28b3XtQojcEQrQiuYGy8aBuRK989gNO2TsLVxFUyrbkqk687cq/MjIjVXitiQ +tH2bHFPwBfHQx/OgaDMje+WTeMDPhp4gAA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgeekgddutdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvuffkgggtugesghdtreertddtvden ucfhrhhomhepofhitghhrggvlhcurfgrqhhuihgvrhcuoehmihgthhgrvghlsehprghquh hivghrrdighiiiqeenucggtffrrghtthgvrhhnpedvtdffteegtdfhuefgvedvtdejgfeu gfeggfejgfdvhefgfeevieektdelkefhgfenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 29 Feb 2024 02:21:08 -0500 (EST) Date: Thu, 29 Feb 2024 16:20:53 +0900 From: Michael Paquier To: Postgres hackers Subject: Propagate sanity checks of ProcessUtility() to standard_ProcessUtility()? Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="W48wypHRhaotZjBh" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --W48wypHRhaotZjBh Content-Type: multipart/mixed; boundary="XNoBAAwkRLY0LdEB" Content-Disposition: inline --XNoBAAwkRLY0LdEB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, It's been brought to me that an extension may finish by breaking the assumptions ProcessUtility() relies on when calling standard_ProcessUtility(), causing breakages when passing down data to cascading utility hooks. Isn't the state of the arguments given something we should check not only in the main entry point ProcessUtility() but also in standard_ProcessUtility(), to prevent issues if an extension incorrectly manipulates the arguments it needs to pass down to other modules that use the utility hook, like using a NULL query string? See the attached for the idea. Thanks, -- Michael --XNoBAAwkRLY0LdEB Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="utility-checks.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index 8de821f960..ee82551dde 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -88,6 +88,20 @@ static void ProcessUtilitySlow(ParseState *pstate, QueryCompletion *qc); static void ExecDropStmt(DropStmt *stmt, bool isTopLevel); =20 + +/* + * Check the state of the arguments given to entry points for utility + * processing. + */ +#define UTILITY_CHECKS \ +do { \ + Assert(IsA(pstmt, PlannedStmt)); \ + Assert(pstmt->commandType =3D=3D CMD_UTILITY); \ + Assert(queryString !=3D NULL); /* required as of 8.4 */ \ + Assert(qc =3D=3D NULL || qc->commandTag =3D=3D CMDTAG_UNKNOWN); \ +} while (0) + + /* * CommandIsReadOnly: is an executable query read-only? * @@ -512,10 +526,7 @@ ProcessUtility(PlannedStmt *pstmt, DestReceiver *dest, QueryCompletion *qc) { - Assert(IsA(pstmt, PlannedStmt)); - Assert(pstmt->commandType =3D=3D CMD_UTILITY); - Assert(queryString !=3D NULL); /* required as of 8.4 */ - Assert(qc =3D=3D NULL || qc->commandTag =3D=3D CMDTAG_UNKNOWN); + UTILITY_CHECKS; =20 /* * We provide a function hook variable that lets loadable plugins get @@ -559,6 +570,8 @@ standard_ProcessUtility(PlannedStmt *pstmt, ParseState *pstate; int readonly_flags; =20 + UTILITY_CHECKS; + /* This can recurse, so check for excessive recursion */ check_stack_depth(); =20 --XNoBAAwkRLY0LdEB-- --W48wypHRhaotZjBh Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIyBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmXgMFUACgkQnvQgOdby QH27+Q/4kxu+d8AZNPmnOo7FNSzB76WI7idel35ZDez7cvN0CZ80R3Y9PeYX49aO bKucVlQyZjM2gA2+avJP+2XAbWH+xlfrNmZWij6cp0YbPB4qzdmvVZBbLbV4nOUm DiUUPJEtdM9UlqImck/W+VHrNqQZP8gp4jTW9406w1q6OKxu7iQf1+V0ZXxfCbu9 GAD7mtdUwtkSGqjup5dJsnOTq4PYMbAU87xBU+OXzjjRm/5OdLVuVbVznTqA91Db G4A1e1v5+pHTEafZ1p5J16MoQDjhO7vD/fpTe9MOQkVJxCjP0BMNcV7g2h/tsjdy mjCmIJaDkjFfU7m6jAOzSWoP2Legpk51lKE8hQfwkdn9kdmwtCGnEc0lYdyBEVYX sPINxzJgYjxXTDreqYUOqixjZ78MZZJWia+OTGcNVWOFOlxKQsg7f69tb2St8s5G gN8z0/4qN/xGxu6BrgTD3mmq84G+/Pt4ucNEypHlE94efpy7UERN44NBtO1J6BDr L0BKQqb/sEU6XDb3+3B5V+YDStTQ4MEXmkuYAIxYeWy2laeoqsAg2+yJ+nWDDqHg irkaQGeKU0UYuY7d7V0NMRtnrq3sTlKKEOsV2XJf5UZg7nRyMUOGS2nFfEqZ2ypd 0RvgGhT403zFr9ASFFY3mwsbb2QD7yp1wTuvhSfYiNGpmJ+HXQ== =LMW9 -----END PGP SIGNATURE----- --W48wypHRhaotZjBh--