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

From
David Laight <hidden>
Date
2026-11-05 11:28:17
Also in
linux-hardening, lkml
Reply to
Mariia Nikitash, 2026-11-04
On Tue,  3 Nov 2026 22:23:18 -0800
Mariia Nikitash [off-list ref] wrote:
quoted hunk ↗ jump to hunk
In preparation for removing the deprecated strlcat() API[1], use
strscpy() to initialize the mouse device name.

The destination is zero-initialized, and the constant string fits
within the buffer. Since the return value is unused, this preserves
the existing behavior.

Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Mariia Nikitash <redacted>
---
 drivers/input/mouse/vsxxxaa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c
index 042a17fe81db..b3a0d7ff5738 100644
--- a/drivers/input/mouse/vsxxxaa.c
+++ b/drivers/input/mouse/vsxxxaa.c
@@ -463,8 +463,8 @@ static int vsxxxaa_connect(struct serio *serio, struct serio_driver *drv)
 
 	mouse->dev = input_dev;
 	mouse->serio = serio;
-	strlcat(mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer",
-		 sizeof(mouse->name));
+	strscpy(mouse->name, "DEC VSXXX-AA/-GA mouse or VSXXX-AB digitizer",
+		sizeof(mouse->name));
You might as well use the 2 argument form.
Moreover, if you use strcpy() you'll get a compile-time error if the
string doesn't fit.
strscpy() will truncate and return an errors.

The other question is whether mouse->name even has to be char[].

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()).

This case is, of course one of the 'better ways' cases.

David
 	snprintf(mouse->phys, sizeof(mouse->phys), "%s/input0", serio->phys);
 
 	input_dev->name = mouse->name;
  
Thread (9 messages) 9 messages, 5 authors, last reply 4d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help