From: David Laight <david.laight.linux@gmail.com>
To: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Petr Mladek <pmladek@suse.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Steven Rostedt <rostedt@goodmis.org>,
Sergey Senozhatsky <senozhatsky@chromium.org>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] lib/vsprintf: Fix to check field_width and precision
Date: Wed, 25 Mar 2026 09:14:47 +0000 [thread overview]
Message-ID: <20260325091447.74e419df@pumpkin> (raw)
In-Reply-To: <20260325101704.f31e0ba4c13ebb1b63b701aa@kernel.org>
On Wed, 25 Mar 2026 10:17:04 +0900
Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:
> On Wed, 25 Mar 2026 09:33:20 +0900
> Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:
>
> > On Tue, 24 Mar 2026 17:24:33 +0000
> > David Laight <david.laight.linux@gmail.com> wrote:
> >
> > > On Tue, 24 Mar 2026 17:45:49 +0100
> > > Petr Mladek <pmladek@suse.com> wrote:
> > >
> > > > On Mon 2026-03-23 13:59:05, David Laight wrote:
> > > ...
> > > > > I've also just fixed nolibc's handling of %*.*s (which is in 'next' since
> > > > > I only wrote it recently), the above is actually broken.
> > > > > Negative 'precision' (all values) are fine, they just request the default.
> > > >
> > > > Great catch! We should clamp the precision to (0, PRECISION_MAX). But we
> > > > should warn only when it is outside of (-PRECISION_MAX, PRECISION_MAX).
> > >
> > > No, you are going to clamp it needs to be to (-1, PRECISION_MAX);
> > > but max(precision, PRECISION_MAX) if fine now the value is being saved
> > > in an int.
> > > And there is no need to warn about changing negative values - they
> > > all mean exactly the same thing.
> >
> > Ah, indeed.
> >
> > "A negative precision is taken as if the precision were omitted."
>
> Hmm, and format_decode() does not accept -1 precision. We need
> another patch to fix it.
>
> spec->precision = -1;
> if (unlikely(*fmt.str == '.')) {
> fmt.str++;
> if (isdigit(*fmt.str)) { <---- isdigit() accepts '0'-'9', not '-'.
> spec->precision = skip_atoi(&fmt.str); <--- this only returns positive value.
> if (spec->precision < 0)
> spec->precision = 0;
That is fine, you aren't allowed a negative value there - just for "%.*d".
David
> } else if (*fmt.str == '*') {
>
> Thanks,
>
next prev parent reply other threads:[~2026-03-25 9:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-21 14:41 [PATCH v3 0/2] lib/vsprintf: Fixes size check Masami Hiramatsu (Google)
2026-03-21 14:41 ` [PATCH v3 1/2] lib/vsprintf: Fix to check field_width and precision Masami Hiramatsu (Google)
2026-03-23 13:27 ` Andy Shevchenko
2026-03-23 13:59 ` David Laight
2026-03-24 16:45 ` Petr Mladek
2026-03-24 17:24 ` David Laight
2026-03-25 0:33 ` Masami Hiramatsu
2026-03-25 1:17 ` Masami Hiramatsu
2026-03-25 9:14 ` David Laight [this message]
2026-03-25 0:26 ` Masami Hiramatsu
2026-03-21 14:41 ` [PATCH v3 2/2] lib/vsprintf: Limit the returning size to INT_MAX Masami Hiramatsu (Google)
2026-03-24 16:50 ` Petr Mladek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260325091447.74e419df@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=mhiramat@kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox