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.
} 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);
}