Re: [PATCH v2 2/6] Input: joystick - use usb_make_subpath()
From: Alejandro Colomar
Date: Thu Oct 22 2026 - 06:08:45 EST
Hi Shihuang,
> Date: 2026-10-22 15:36:39+0800
> From: Shihuang Liu <shlomojune6@xxxxxxxxx>
>
[...]
> > > - usb_make_path(udev, pxrc->phys, sizeof(pxrc->phys));
> > > - strlcat(pxrc->phys, "/input0", sizeof(pxrc->phys));
> > > + usb_make_subpath(udev, pxrc->phys, sizeof(pxrc->phys), "input0");
> >
> > To be honest, I think the composed approach is more readable. You don't
> > need to learn a new _subpath function with all the details it has.
> >
> > Everyone knows what a str*cat() (or str*cpy, FWIW) function does.
> >
> > I'd rather improve this by adding strscat(). The reason for removing
> > strlcat(3) is that it is vulnerable to DoS, and that it is inefficient,
> > but it is good at producing readable code, and a replacement should not
> > degrade that.
> >
> >
> > Have a lovely day!
> > Alex
> >
> Besides that, strscat() has other issues:
>
> - The `sizeof(buf) - len` arithmetic is a classic source of
> off-by-one bugs.
> - any future change means re-deriving the offsets all over again.
The whole point of str*cat() functions is that you don't need to derive
the offsets at all. Just look at the strlcat(3) code above: it doesn't
do any length calculations.
> I'd prefer to avoid strscat() here.
>
> Thanks
> Shihuang
Cheers,
Alex
--
<https://www.alejandro-colomar.es>
Attachment:
signature.asc
Description: PGP signature