Re: Invisible PROMPT2 - Mailing list pgsql-hackers

From Thomas Munro
Subject Re: Invisible PROMPT2
Date
Msg-id CA+hUKGL23CGmnno5TztLd58Dtat5QHKzA0F72Pkv+J4TSjgu4A@mail.gmail.com
Whole thread Raw
In response to Re: Invisible PROMPT2  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Invisible PROMPT2  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Tue, Nov 19, 2019 at 6:21 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Thomas Munro <thomas.munro@gmail.com> writes:
> > Yeah.  Maybe pg_wcswidth() would be OK though, and it's available in
> > psql, though I guess you'd have to make a copy with the escaped bits
> > stripped out.
>
> Right, you should use pg_wcswidth() or the underlying PQdsplen() function
> to compute display width.  The latter might be more convenient since
> you could apply it character by character rather than making a copy
> of the string.

Right, a PQdsplen()/PQmblen() loop works nicely, as attached.

I spotted a potential problem: I suppose I could write a PROMPT1 that
includes an invalid multibyte sequence at the end of the buffer and
trick PQmblen() or PQdsplen() into reading a few bytes past the end.
Two defences against that would be (1) use pg_encoding_verifymb()
instead of PQmblen() and (2) use pg_encoding_max_length() to make sure
you can't get close enough to the end of the buffer, but neither of
those functions are available to psql.

Attachment

pgsql-hackers by date:

Previous
From: Fabien COELHO
Date:
Subject: Re: segfault in geqo on experimental gcc animal
Next
From: Jeremy Finzel
Date:
Subject: physical slot xmin dependency on logical slot?