pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix ecpg's mishandling of B'...' and X'...' literals.
Date: Sat, 07 Nov 2020 20:03:57 +0000
Message-ID: <E1kbURJ-00056c-12@gemulon.postgresql.org> (raw)

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(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1kbURJ-00056c-12@gemulon.postgresql.org>
Permalink:  ../E1kbURJ-00056c-12@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kbURJ-00056c-12@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix ecpg's mishandling of B'...' and X'...' literals.
  In-Reply-To: <E1kbURJ-00056c-12@gemulon.postgresql.org>
  References: <E1kbURJ-00056c-12@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox