Re: [PATCH v5 1/2] lib/vsprintf: Fix to check field_width and precision
From: Google
Date: Thu Mar 26 2026 - 08:04:17 EST
On Thu, 26 Mar 2026 11:57:46 +0200
Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
> On Wed, Mar 25, 2026 at 10:27:41PM +0900, Masami Hiramatsu (Google) wrote:
>
> > Check the field_width and presition correctly. Previously it depends
> > on the bitfield conversion from int to check out-of-range error.
> > However, commit 938df695e98d ("vsprintf: associate the format state
> > with the format pointer") changed those fields to int.
> > We need to check the out-of-range correctly without bitfield
> > conversion.
>
> ...
>
> > +static void
> > +set_field_width(struct printf_spec *spec, int width)
>
> One line.
>
Ah, OK.
> static void set_field_width(struct printf_spec *spec, int width)
>
> > +{
> > + spec->field_width = clamp(width, -FIELD_WIDTH_MAX, FIELD_WIDTH_MAX);
> > + WARN_ONCE(spec->field_width != width, "field width %d out of range",
> > + width);
>
> I would also make it one line for readability.
>
> WARN_ONCE(spec->field_width != width, "field width %d out of range", width);
OK.
>
> > +}
> > +
> > +static void
> > +set_precision(struct printf_spec *spec, int prec)
>
> One line
>
> static void set_precision(struct printf_spec *spec, int prec)
OK, let me update it.
Thanks for review!
>
> > +{
> > + spec->precision = clamp(prec, 0, PRECISION_MAX);
> > + WARN_ONCE(spec->precision < prec, "precision %d too large", prec);
> > +}
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
--
Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx>