pgsql: Fix ecpg's mishandling of B'...' and X'...' literals.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix ecpg's mishandling of B'...' and X'...' literals.
Date: 2020-11-07 20:03:57
Message-ID: E1kbURJ-00056c-12@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix ecpg's mishandling of B'...' and X'...' literals.

These were broken in multiple ways:

* The xbstart and xhstart lexer actions neglected to set
"state_before_str_start" before transitioning to the xb/xh states,
thus possibly resulting in "internal error: unreachable state" later.

* The test for valid string contents at the end of xb state was flat out
wrong, as it accounted incorrectly for the "b" prefix that the xbstart
action had injected. Meanwhile, the xh state had no such check at all.

* The generated literal value failed to include any quote marks.

* The grammar did the wrong thing anyway, typically ignoring the
literal value and emitting something else, since BCONST and XCONST
tokens were handled randomly differently from SCONST tokens.

The first of these problems is evidently an oversight in commit
7f380c59f, but the others seem to be very ancient. The lack of
complaints shows that ECPG users aren't using these syntaxes much
(although I do vaguely remember one previous complaint).

As written, this patch is dependent on 7f380c59f, so it can't go
back further than v13. Given the shortage of complaints, I'm not
excited about adapting the patch to prior branches.

Report and patch by Shenhao Wang (test case adjusted by me)

Discussion: https://postgr.es/m/d6402f1bacb74ecba22ef715dbba17fd@G08CNEXMBPEKD06.g08.fujitsu.local

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1e3868ab3bef5cfa0f4d44a6937a880be7a3a482

Modified Files
--------------
src/interfaces/ecpg/preproc/ecpg.trailer | 4 ++--
src/interfaces/ecpg/preproc/ecpg.type | 2 ++
src/interfaces/ecpg/preproc/parse.pl | 1 +
src/interfaces/ecpg/preproc/pgc.l | 12 +++++++-----
src/interfaces/ecpg/test/expected/preproc-strings.c | 12 +++++++++++-
src/interfaces/ecpg/test/expected/preproc-strings.stderr | 10 ++++++++++
src/interfaces/ecpg/test/expected/preproc-strings.stdout | 1 +
src/interfaces/ecpg/test/preproc/strings.pgc | 5 +++++
8 files changed, 39 insertions(+), 8 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2020-11-07 20:27:45 pgsql: Doc: small release note updates.
Previous Message Peter Eisentraut 2020-11-07 11:32:24 pgsql: Move catalog toast table declarations