Re: [PATCH v4 2/2] kallsyms: Don't leak pointers for unresolved symbols

From: Andy Shevchenko

Date: Mon Oct 19 2026 - 07:07:33 EST


On Mon, Oct 19, 2026 at 12:50:25PM +0200, Sebastian Andrzej Siewior wrote:
> On 2026-10-19 13:34:35 [+0300], Andy Shevchenko wrote:
> > > +int snprintf_default_pointer(char *buf, unsigned int len, const void *ptr)
> > > +{
> > > + struct printf_spec spec = {
> > > + .base = 10,
> > > + .precision = -1,
> > > + .field_width = -1,
> > > + };
> >
> > Isn't it the same as default_dec_spec?

> Except for .field_width, yes.

You can update it there. I think in all other cases (I briefly checked, but
haven't run any smoke test with KUnit) it should be an equivalent.

> > > + unsigned int w;
> > > + char *endp;
> > > +
> > > + endp = default_pointer(buf, buf + len, ptr, spec);
> > > + w = min_t(unsigned int, len - 1, endp - buf);

This also won't properly work for len = 0, I assume? So one can't make
something like kasprintf() on top of this.

> > May we avoid min_t()?
>
> min() complains about signedness (len unsigned and ptr diff signed).
> endp is >= buf so it will be unsigned.
> An alternative would be manual comparison if the buffer size has been
> exceeded or not and act upon it but this looks simpler.

It looks simpler, it looks wrong :-)

> > > + buf[w] = '\0';
> > > + return endp - buf;
> > > +}

--
With Best Regards,
Andy Shevchenko