postgres.git / summary / log / commit / refs

commit    e7e1835e6b026589c8d0650dda4cd1ec8e0e29ea
Author:   Fujii Masao <fujii@postgresql.org>
Date:     Fri Nov 20 06:12:30 2026 +0000

    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 <lic@highgo.com>
    Reviewed-by: Kirill Reshke <reshkekirill@gmail.com>
    Reviewed-by: Ishjaap Singh <ishjaap.singh07@gmail.com>
    Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
    Discussion: https://postgr.es/m/0B33F84F-6AA3-4A39-A45D-D8F31D4E44D8@gmail.com
    Backpatch-through: 15


src/bin/psql/prompt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c index 681574bee79..1c79a829090 100644 --- a/src/bin/psql/prompt.c +++ b/src/bin/psql/prompt.c @@ -333,7 +333,9 @@ get_prompt(promptStatus_t prompt_status, ConditionalStack cstack) (void) pg_strip_crlf(buf); pfree(file); - p += cmdend + 1; + p += cmdend; + if (p[1] != '\0') + p++; break; } @@ -348,7 +350,9 @@ get_prompt(promptStatus_t prompt_status, ConditionalStack cstack) if (val) strlcpy(buf, val, sizeof(buf)); pfree(name); - p += nameend + 1; + p += nameend; + if (p[1] != '\0') + p++; break; } [parent: d94964f14f39]