Re: [PATCH v3 0/4] Make sscanf() stricter

From: Andy Shevchenko
Date: Mon Jun 12 2023 - 17:05:03 EST


On Mon, Jun 12, 2023 at 04:25:01PM -0400, Demi Marie Obenour wrote:
> On Mon, Jun 12, 2023 at 02:59:38PM +0300, Alexey Dobriyan wrote:
> > > + bool _placeholder;
> > > + return simple_strntoull(cp, INT_MAX, endp, base, &_placeholder);
> >
> > This can be done without introducing dummy variables:
> >
> > void f(bool *b)
> > {
> > }
> >
> > f((bool[1]){});
>
> This is more consise, but (at least to me) significantly less readable.
>
> > > > lib/vsprintf.c:3727:26: error: unknown conversion type character ‘!’ in format [-Werror=format=]
> > > So NAK.
> >
> > Yeah, ! should go after format specifier like it does for %p.
>
> I hadn't considered that. Is the typical approach in Linux to use e.g.
> %d%[!] if one wants a literal '!'?

It might be that the cleanest way we have is to create %p-like extensions to
sscanf(). %p takes alnum as parameter and that is usually works since it makes
a little sense to attach alnum suffix to the pointer.

(I don't like to have %dX, where X is alnum as we expanding our hack to
something which people don't expect to be altered even in the kernelm, you may
refer to the discussion about %de for printing errors)


--
With Best Regards,
Andy Shevchenko