From: | Thomas Munro <thomas(dot)munro(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, David Fetter <david(at)fetter(dot)org>, ilmari(at)ilmari(dot)org, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Invisible PROMPT2 |
Date: | 2019-11-18 21:07:33 |
Message-ID: | CA+hUKGL23CGmnno5TztLd58Dtat5QHKzA0F72Pkv+J4TSjgu4A@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Tue, Nov 19, 2019 at 6:21 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Thomas Munro <thomas(dot)munro(at)gmail(dot)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 | Content-Type | Size |
---|---|---|
v2-0001-Allow-invisible-PROMPT2-in-psql.patch | application/octet-stream | 3.3 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Jeremy Finzel | 2019-11-18 21:36:47 | physical slot xmin dependency on logical slot? |
Previous Message | Fabien COELHO | 2019-11-18 20:08:06 | Re: segfault in geqo on experimental gcc animal |