[PATCH 4/7] ALSA: caiaq: replace strlcat() with strscpy()

Mahad Ibrahim <[email protected]>
Newsgroups org.kernel.vger.linux-sound,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
usb_make_path() fills cdev->phys with the device path, and "/input0"
was then appended with strlcat().

Take the length of the path with strlen() and write the suffix at
that offset with strscpy(), passing the remaining space in the
buffer.

cdev->phys is NUL-terminated by usb_make_path(), so the offset is
within the array and the size passed to strscpy() is at least one.
The suffix lands in the same place and truncates at the same point.

Signed-off-by: Mahad Ibrahim <[email protected]>
---
 sound/usb/caiaq/input.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/usb/caiaq/input.c b/sound/usb/caiaq/input.c
index 8d924330c54c..fd4c80c7530c 100644
--- a/sound/usb/caiaq/input.c
+++ b/sound/usb/caiaq/input.c
@@ -604,14 +604,15 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *cdev)
 {
 	struct usb_device *usb_dev = cdev->chip.dev;
 	struct input_dev *input;
-	int i, ret = 0;
+	int i, len, ret = 0;
 
 	input = input_allocate_device();
 	if (!input)
 		return -ENOMEM;
 
 	usb_make_path(usb_dev, cdev->phys, sizeof(cdev->phys));
-	strlcat(cdev->phys, "/input0", sizeof(cdev->phys));
+	len = strlen(cdev->phys);
+	strscpy(cdev->phys + len, "/input0", sizeof(cdev->phys) - len);
 
 	input->name = cdev->product_name;
 	input->phys = cdev->phys;
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.