From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Thomas Munro <thomas(dot)munro(at)gmail(dot)com> |
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 23:09:05 |
Message-ID: | 1233.1574118545@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Thomas Munro <thomas(dot)munro(at)gmail(dot)com> writes:
> 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.
You should follow the logic in pg_wcswidth: compute PQmblen() first,
and bail out if it's more than the remaining string length, otherwise
it's ok to apply PQdsplen().
It might be a good idea to explicitly initialize last_prompt1_width to
zero, for clarity.
Should the user docs explicitly say "of the same width as the most recent
output of PROMPT1", as you have in the comments? That seems a more
precise specification, and it will eliminate some questions people will
otherwise ask.
LGTM otherwise.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Maciek Sakrejda | 2019-11-18 23:39:33 | Re: Duplicate Workers entries in some EXPLAIN plans |
Previous Message | Andres Freund | 2019-11-18 22:12:54 | Re: physical slot xmin dependency on logical slot? |