Re: [PATCH] char: xillybus: use strscpy() in init_chrdev

From: Thorsten Blum

Date: Tue Apr 28 2026 - 05:37:16 EST


On Tue, Apr 28, 2026 at 10:37:49AM +0200, Eli Billauer wrote:
> Hello,
>
> On 27/04/2026 19:37, Thorsten Blum wrote:
>
> > if (!enumerate)
> > - snprintf(unit->name, UNITNAMELEN, "%s", prefix);
> > + strscpy(unit->name, prefix);
> > for (i = 0; enumerate; i++) {
> > snprintf(unit->name, UNITNAMELEN, "%s_%02d",
>
> snprintf() is used deliberately for code clarity: It makes a simple visual
> contrast with the use of snprintf() three rows below. As this call takes
> place only once for each physical hardware device handled by the driver, the
> advantage in optimizing this function call is negligible.
>
> And even though it's formally OK to use strscpy() with two arguments, and
> let the compilation machinery find out the length of the char array, I have
> to admit that it gives me the chills. Buffer overflow and that.

You probably mean strcpy()? strscpy() is safe regarding buffer overflow.