Re: [PATCH v3 2/2] lib/vsprintf: Limit the returning size to INT_MAX

From: Petr Mladek

Date: Tue Mar 24 2026 - 12:57:35 EST


On Sat 2026-03-21 23:41:21, Masami Hiramatsu (Google) wrote:
> From: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>
>
> The return value of vsnprintf() can overflow INT_MAX and return
> a minus value. In the @size is checked input overflow, but it does
> not check the output, which is expected required size.
>
> This should never happen but it should be checked and limited.
>
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>

It looks good to me. And the WARN_ON_ONCE() looks acceptable to me.
It is already used for checking the input size parameter in
vsnprintf(), and bstr_printf().

Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>

Best Regards,
Petr