psql: Fix out-of-bounds reads in prompt expansion

psql could crash when a custom prompt contained a %:name: or
%`command` escape without its closing delimiter.

This happened because prompt expansion assumed that the closing
delimiter was present and read past the end of the prompt string
when it was missing.

Fix this by checking for the closing delimiter before advancing
past it.

Backpatch to all supported versions.

Author: Chao Li <[email protected]>
Reviewed-by: Kirill Reshke <[email protected]>
Reviewed-by: Ishjaap Singh <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Discussion: https://postgr.es/m/[email protected]
Backpatch-through: 15

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/69d0abc4f950082609458e5973a92b8aa1e8ffaa

Modified Files
--------------
src/bin/psql/prompt.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

Reply via email to