Re: Invisible PROMPT2 - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Invisible PROMPT2
Date
Msg-id 1233.1574118545@sss.pgh.pa.us
Whole thread Raw
In response to Re: Invisible PROMPT2  (Thomas Munro <thomas.munro@gmail.com>)
Responses Re: Invisible PROMPT2  (Thomas Munro <thomas.munro@gmail.com>)
List 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



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: physical slot xmin dependency on logical slot?
Next
From: Maciek Sakrejda
Date:
Subject: Re: Duplicate Workers entries in some EXPLAIN plans