Re: Invisible PROMPT2
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>,
Kyotaro Horiguchi <horikyota.ntt@gmail.com>,
David Fetter <david@fetter.org>, ilmari@ilmari.org,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2019-11-18T23:09:05Z
Lists: pgsql-hackers
Thomas Munro <thomas.munro@gmail.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
Commits
-
psql: Fix %w length in PROMPT2 when PROMPT1 contains a newline.
- 1713a0013f90 13.0 landed
-
Allow invisible PROMPT2 in psql.
- 7f338369ca62 13.0 landed