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 <[email protected]> Reviewed-by: Noah Misch <[email protected]> Backpatch-through: 14 Security: CVE-2026-6464 Branch ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/900894d35ca72bfba853447ca986bdced4ad993b Author: Tom Lane <[email protected]> Modified Files -------------- src/bin/psql/command.c | 16 +++++++--------- src/bin/psql/psqlscanslash.h | 5 +++++ src/bin/psql/psqlscanslash.l | 38 +++++++++++++++++++++++++++++++++++++ src/fe_utils/conditional.c | 34 +++++++++++++++++++++++++++++++++ src/include/fe_utils/conditional.h | 17 +++++++++++------ src/include/fe_utils/psqlscan.h | 3 +++ src/include/fe_utils/psqlscan_int.h | 17 +++++++++++++++++ src/test/regress/expected/psql.out | 16 ++++++++++++++++ src/test/regress/sql/psql.sql | 11 +++++++++++ src/tools/pgindent/typedefs.list | 1 + 10 files changed, 143 insertions(+), 15 deletions(-)
