Skip to contentSkip to conversation

usbvideo: limit the length of string creation

PATCH In review Németh Márton 2 participants 2 messages Nov 21, 2009 – Dec 1, 2009 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usbvideo: limit the length of string creation

From: Márton Németh <[email protected]>

Use strlcat() to append a string to the previously created first part. The strlcat() function limits the size of the string to the whole destination buffer.

The semantic match that finds this kind of problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression dev;
expression phys;
expression str;
expression size;
@@
usb_make_path(dev, phys, size);
- strncat(phys, str, size);
+ strlcat(phys, str, size);
// </smpl>

---

drivers/media/video/usbvideo/konicawc.c 2009-11-21 17:48:52.000000000 +0100 renamed from drivers/media/video/usbvideo/konicawc.c 2009-09-10 00:13:59.000000000 +0200 +1 -1
diff -u -p a/drivers/media/video/usbvideo/konicawc.c b/drivers/media/video/usbvideo/konicawc.c
@@ -225,7 +225,7 @@ static void konicawc_register_input(stru
 	int error;
 
 	usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
-	strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
+	strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
 
 	cam->input = input_dev = input_allocate_device();
 	if (!input_dev) {
drivers/media/video/usbvideo/quickcam_messenger.c 2009-11-21 17:48:53.000000000 +0100 renamed from drivers/media/video/usbvideo/quickcam_messenger.c 2009-09-10 00:13:59.000000000 +0200 +1 -1
diff -u -p a/drivers/media/video/usbvideo/quickcam_messenger.c b/drivers/media/video/usbvideo/quickcam_messenger.c
@@ -89,7 +89,7 @@ static void qcm_register_input(struct qc
 	int error;
 
 	usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
-	strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
+	strlcat(cam->input_physname, "/input0", sizeof(cam->input_physname));
 
 	cam->input = input_dev = input_allocate_device();
 	if (!input_dev) {
Acked-by on v1 1/1
#1 lore raw
Quoted 21 lines · On Saturday 21 November 2009 18:02:56 Németh Márton wrote:

From: Márton Németh <[email protected]>

Use strlcat() to append a string to the previously created first part. The strlcat() function limits the size of the string to the whole destination buffer.

The semantic match that finds this kind of problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression dev;
expression phys;
expression str;
expression size;
@@

(quoted diff) +1 -1
 	usb_make_path(dev, phys, size);
-	strncat(phys, str, size);
+	strlcat(phys, str, size);

// </smpl>

Quoted 1 line
Signature · 3 lines
Regards,

Laurent Pinchart