postgres.git / summary / log / commit / refs
commit f772e165b87b2a4c9b13aec3b6795d6215147147
Author: Fujii Masao <fujii@postgresql.org>
Date: Fri Nov 20 06:13:22 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 509e6422b7e..476e6108161 100644
--- a/src/bin/psql/prompt.c
+++ b/src/bin/psql/prompt.c
@@ -279,7 +279,9 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
(void) pg_strip_crlf(buf);
free(file);
- p += cmdend + 1;
+ p += cmdend;
+ if (p[1] != '\0')
+ p++;
break;
}
@@ -294,7 +296,9 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
if (val)
strlcpy(buf, val, sizeof(buf));
free(name);
- p += nameend + 1;
+ p += nameend;
+ if (p[1] != '\0')
+ p++;
break;
}
[parent: e5b33ff4514c]