Re: [PATCH] Input: mouse: vsxxxaa: Replace strlcat() with strscpy()

From: David Laight

Date: Thu Nov 05 2026 - 15:56:31 EST


On Thu, 5 Nov 2026 12:49:59 +0100
Alejandro Colomar <alx+linux-hardening@xxxxxxxxxx> wrote:

> > Personally I think that while there are issues with strlcat()
> > (mostly to do with its return value), and that there are often
> > much better (and faster - so sprintf is out) ways of getting
> > the same result, the deprecation really needs to propose a
> > sensible alternative (not inlined strlen() + strscpy()).
>
> One alternative would be to add strscat(), with the obvious internal
> strlen(3). This would be a drop-in replacement, and wouldn't have the
> issues of strlcat(3) --mainly, the DoS vulnerability which is
> consequence of the return value, and also the more difficult error
> handling of doing '>=sizeof(...)' than '<0'--.

I've had thoughts of a more general function - but I've not tried to
write it.

int str_append(char *dest, size_t dest_sz, size_t dest_off, const char *src, size_t src_max_len);

Where dest_sz is usually sizeof(*dest) and the header can substitute that for
a constant zero.
dest_off would similarly default to strlen(dest), if -ve the function would
return that value immediately.
src_max_len would be used for an effective strnlen(src, src_max_len).

The idea would be that calls like:
char tgt[100];
len = str_append(tgt, 0, strscpy(tgt, src_1), src_2, 0);
would append src_1 and src_2 in tgt returning -ve on overflow.
(Further chaining would then work.)

But, as I said, I've not tried to write it or see what it would look like in use.

David