From: Christopher Faulet Date: Fri, 20 Nov 2026 16:16:44 +0000 (+0100) Subject: BUG/MINOR: vars: fix missing string termination in get var on too long values X-Git-Url: https://git.kaiwu.me/http/%7B@url%7D?a=commitdiff_plain;h=1021db1d76e7e69d04819a7a320062dea1161450;p=haproxy.git BUG/MINOR: vars: fix missing string termination in get var on too long values vars_parse_cli_get_var() builds the output for the CLI's "get var" in the shared trash chunk using b_putchr(), which silently drops bytes once the buffer is full. For a value long enough to exhaust trash mid-loop, the trailing '>' and the terminating NUL were dropped, leaving trash.area without any NUL within its bounds. cli_msg() only stores the pointer and the string is later read with ist() (i.e. strlen) in cli_output_msg(), reading past the buffer. Now the loop stops before the last byte, and the terminating NUL is always written within bounds, truncating the output if needed. This patch should fix the issue #3592. It could be backported to all supported versions. --- diff --git a/src/vars.c b/src/vars.c index 0b4d506af..29ca311ab 100644 --- a/src/vars.c +++ b/src/vars.c @@ -1817,15 +1817,17 @@ static int vars_parse_cli_get_var(char **args, char *payload, struct appctx *app } else { /* Display the displayable chars*. */ b_putchr(&trash, '<'); - for (i = 0; i < smp.data.u.str.data; i++) { + for (i = 0; i < smp.data.u.str.data && trash.data < trash.size - 1; i++) { if (isprint((unsigned char)smp.data.u.str.area[i])) b_putchr(&trash, smp.data.u.str.area[i]); else b_putchr(&trash, '.'); } - b_putchr(&trash, '>'); - b_putchr(&trash, '\n'); - b_putchr(&trash, 0); + if (trash.data < trash.size - 1) + b_putchr(&trash, '>'); + if (trash.data < trash.size - 1) + b_putchr(&trash, '\n'); + trash.area[trash.data < trash.size ? trash.data : trash.size - 1] = 0; } return cli_msg(appctx, LOG_INFO, trash.area); }