agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Noah Misch <noah@leadboat.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Save/restore more lexer state when skipping text due to \if.
Date: Mon, 10 Aug 2026 13:41:23 +0000
Message-ID: <E1wtQFn-00000000y5j-0th8@gemulon.postgresql.org> (raw)

Save/restore more lexer state when skipping text due to \if.

When we implemented \if ... \endif in psql, we arranged to
save/restore the lexer's parenthesis depth counter across any chunk
of input that we're ignoring.  At the time, that was sufficient,
because no other part of PsqlScanState could need to be restored to
its prior value.  However, commit e717a9a18 and follow-ons added
more state fields that ought to be restored to their prior values.
A problem would only be observed if someone tries to \if out a
portion of a CREATE FUNCTION/PROCEDURE command that is relevant to
BEGIN/END matching, which seems like a pretty unusual usage, so the
lack of field reports isn't surprising.  Nonetheless it's a bug.

To fix, replace the simple counter field in ConditionalStack
entries with a pointer to a struct defined by psqlscan_int.h.
(In the back branches, keep the old field and associated functions
to minimize the risk of API/ABI breakage, even though it seems
unlikely that any third-party code is using this.  Making the
new struct private to psqlscan-related code should prevent API/ABI
issues for future additions of this type.)

In itself this is only a minor bug fix, but it's prerequisite
infrastructure for the fix for CVE-2026-6464, which will add
another such field.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Noah Misch <noah@leadboat.com>
Backpatch-through: 14
Security: CVE-2026-6464

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/8cf01e213ccc33e22e87b49e2711e4a83b4f01e0
Author: Tom Lane <tgl@sss.pgh.pa.us>

Modified Files
--------------
src/bin/psql/command.c              | 16 +++++++--------
src/bin/psql/psqlscanslash.h        |  5 +++--
src/bin/psql/psqlscanslash.l        | 40 +++++++++++++++++++++++++++++--------
src/fe_utils/conditional.c          | 28 ++++++++++++++++----------
src/include/fe_utils/conditional.h  | 16 +++++++--------
src/include/fe_utils/psqlscan.h     |  3 +++
src/include/fe_utils/psqlscan_int.h | 20 +++++++++++++++++++
src/test/regress/expected/psql.out  | 16 +++++++++++++++
src/test/regress/sql/psql.sql       | 11 ++++++++++
src/tools/pgindent/typedefs.list    |  1 +
10 files changed, 119 insertions(+), 37 deletions(-)



view thread (5+ messages)  latest in thread

Message-ID: <E1wtQFn-00000000y5j-0th8@gemulon.postgresql.org>
Permalink:  ../E1wtQFn-00000000y5j-0th8@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wtQFn-00000000y5j-0th8@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: noah@leadboat.com, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Save/restore more lexer state when skipping text due to \if.
  In-Reply-To: <E1wtQFn-00000000y5j-0th8@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox