[PATCH 0/1] lib/vsprintf: Fixes size check

Masami Hiramatsu (Google) posted 1 patch 2 weeks, 1 day ago
Only 0 patches received!
There is a newer version of this series
lib/vsprintf.c |    8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
[PATCH 0/1] lib/vsprintf: Fixes size check
Posted by Masami Hiramatsu (Google) 2 weeks, 1 day ago
Hi,

Here is a pair of patches to fix vsnprintf().

 - Fix to limit the size of width and precision.
 - Warn if the return size is over INT_MAX.

Recently we discussed snprintf() usage in bootconfig and found snprintf()
design has a problem[1]. It returns the required or printed size in 'int'
but the maxlen is passed by 'size_t'. The maxlen is already limited by
INT_MAX, but if the expected print size becomes bigger than INT_MAX,
it can return negative value. We also found width and precision size check
does not work.

[1] https://lore.kernel.org/all/20260317121507.30735331@gandalf.local.home/

Thank you,

---

Masami Hiramatsu (Google) (2):
      lib/vsprintf: Fix to check field_width and precision
      lib/vsprintf: Limit the returning size to INT_MAX


 lib/vsprintf.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
Re: [PATCH 0/1] lib/vsprintf: Fixes size check
Posted by Masami Hiramatsu (Google) 2 weeks, 1 day ago
Sorry, I made a mistake on sending series. See v2.

On Fri, 20 Mar 2026 12:52:14 +0900
"Masami Hiramatsu (Google)" <mhiramat@kernel.org> wrote:

> Hi,
> 
> Here is a pair of patches to fix vsnprintf().
> 
>  - Fix to limit the size of width and precision.
>  - Warn if the return size is over INT_MAX.
> 
> Recently we discussed snprintf() usage in bootconfig and found snprintf()
> design has a problem[1]. It returns the required or printed size in 'int'
> but the maxlen is passed by 'size_t'. The maxlen is already limited by
> INT_MAX, but if the expected print size becomes bigger than INT_MAX,
> it can return negative value. We also found width and precision size check
> does not work.
> 
> [1] https://lore.kernel.org/all/20260317121507.30735331@gandalf.local.home/
> 
> Thank you,
> 
> ---
> 
> Masami Hiramatsu (Google) (2):
>       lib/vsprintf: Fix to check field_width and precision
>       lib/vsprintf: Limit the returning size to INT_MAX
> 
> 
>  lib/vsprintf.c |    8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> --
> Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>