From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
To: David Laight <david.laight.linux@gmail.com>
Cc: Petr Mladek <pmladek@suse.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
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:33:20 +0900 [thread overview]
Message-ID: <20260325093320.5bc786394face92aadbe4e4b@kernel.org> (raw)
In-Reply-To: <20260324172433.05292942@pumpkin>
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."
> There isn't actually any need to worry about large precision values
> for %s - they request truncation, precision only increases the output
> for numbers.
>
> >
> > > So the patch needs a big fat NACK...
> >
> > What is an acceptable solution then, please?
>
> You could do:
> spec->precision = clamp(prec, -1, PRECISION_MAX);
> if (spec->precision < prec)
> WARN(...);
>
> David
Ah, that looks good to me. Let me update it.
Thanks,
>
> >
> > Frankly, I would like to stay on earth. This started as a simple fix
> > of a regression added a year ago. For me, any solution which
> > restores the year old behavior is good enough.
> >
> > We might need to find another volunteer to implement a better
> > solution, e.g. the new non-panicing MSG_AND_BT() macro.
> >
> > Alternatively, we could remove the WARN_ONCE() completely.
> > It looks acceptable for me. But Rasmus would need to agree as well.
> >
> > Best Regards,
> > Petr
>
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next prev parent reply other threads:[~2026-03-25 0:33 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 [this message]
2026-03-25 1:17 ` Masami Hiramatsu
2026-03-25 9:14 ` David Laight
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=20260325093320.5bc786394face92aadbe4e4b@kernel.org \
--to=mhiramat@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=david.laight.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.