pgsql: Prevent mis-encoding of "trailing junk after numeric literal" er

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Prevent mis-encoding of "trailing junk after numeric literal" er
Date: 2024-09-05 16:42:45
Message-ID: E1smFZE-000HB2-8J@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Prevent mis-encoding of "trailing junk after numeric literal" errors.

Since commit 2549f0661, we reject an identifier immediately following
a numeric literal (without separating whitespace), because that risks
ambiguity with hex/octal/binary integers. However, that patch used
token patterns like "{integer}{ident_start}", which is problematic
because {ident_start} matches only a single byte. If the first
character after the integer is a multibyte character, this ends up
with flex reporting an error message that includes a partial multibyte
character. That can cause assorted bad-encoding problems downstream,
both in the report to the client and in the postmaster log file.

To fix, use {identifier} not {ident_start} in the "junk" token
patterns, so that they will match complete multibyte characters.
This seems generally better user experience quite aside from the
encoding problem: for "123abc" the error message will now say that
the error appeared at or near "123abc" instead of "123a".

While at it, add some commentary about why these patterns exist
and how they work.

Report and patch by Karina Litskevich; review by Pavel Borisov.
Back-patch to v15 where the problem came in.

Discussion: https://postgr.es/m/CACiT8iZ_diop=0zJ7zuY3BXegJpkKK1Av-PU7xh0EDYHsa5+=g@mail.gmail.com

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7dcbf0afa28cc8c3dd83bef0428a18ac177f129e

Modified Files
--------------
src/backend/parser/scan.l | 44 +++++++++++++++++---------------
src/fe_utils/psqlscan.l | 41 ++++++++++++++++-------------
src/interfaces/ecpg/preproc/pgc.l | 41 ++++++++++++++++-------------
src/test/regress/expected/numerology.out | 10 ++++----
4 files changed, 74 insertions(+), 62 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Jeff Davis 2024-09-05 19:22:48 pgsql: Be more careful with error paths in pg_set_regex_collation().
Previous Message Daniel Gustafsson 2024-09-05 13:35:31 pgsql: Fix handling of NULL return value in typarray lookup