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 1toTjx-00BJO8-Ls for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Mar 2025 20:47:18 +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 1toTjx-004Iq1-LJ for pgsql-bugs@arkaria.postgresql.org; Sat, 01 Mar 2025 20:47:16 +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 1toTjx-004IoA-Cx for pgsql-bugs@lists.postgresql.org; Sat, 01 Mar 2025 20:47:15 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1toTju-000P9t-0T for pgsql-bugs@lists.postgresql.org; Sat, 01 Mar 2025 20:47:15 +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 521KlCVe3068027; Sat, 1 Mar 2025 15:47:12 -0500 From: Tom Lane To: tharakan@gmail.com cc: pgsql-bugs@lists.postgresql.org, Masahiko Sawada , Bertrand Drouvot Subject: Re: BUG #18828: Crash when pg_get_logical_snapshot_meta() passed empty string In-reply-to: <18828-0f4701c635064211@postgresql.org> References: <18828-0f4701c635064211@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Sat, 01 Mar 2025 18:41:19 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3068025.1740862032.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sat, 01 Mar 2025 15:47:12 -0500 Message-ID: <3068026.1740862032@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > Passing an empty string to the recently added extension function > pg_get_logical_snapshot_meta() triggers PANIC / Abort. Thanks for noticing. It looks like this function is far too trusting of its input. Another way to crash it is to point to a directory: regression=3D# SELECT pg_get_logical_snapshot_meta('../snapshots'); PANIC: could not open file "pg_logical/snapshots/../snapshots": Is a dire= ctory server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. This example incidentally shows that it's not sanitizing the request to prevent reference to files outside the snapshots directory, which possibly would be a security bug down the road. I realize that we restrict access to the function, but still we shouldn't be *this* trusting of the argument. Possibly some of the defense for this ought to be in SnapBuildRestoreSnapshot: it looks like that function isn't considering the possibility that OpenTransientFile will succeed on a directory. Does it have any other callers passing less-than-fully-trustworthy paths? Another interesting question is why the error is being promoted to PANIC. That sure seems unnecessary, and there's a comment in SnapBuildRestoreSnapshot that claims it won't happen. regards, tom lane