Skip to contentSkip to conversation

konicawc.c: possible buffer overflow while use strncat

PATCH New [email protected] 1 participant 1 message Nov 17, 2009 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 konicawc.c: possible buffer overflow while use strncat

From: Alexander Strakh <[email protected]>

In driver ./drivers/media/video/usbvideo/konicawc.c in line 227:

227 usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));

After this line we use strncat:

228 strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));

where sizeof(cam->input_physname) returns length of cam->input_phisname without length for null-symbol. But this parameter must be - "maximum numbers of bytes to copy", i.e.:
sizeof(cam->input_physname)-strlen(cam->input_physname)-1.

In this case, after call to usb_make_path the similar drivers use strlcat.

Like in drivers/hid/usbhid/hid-core.c:
1152 usb_make_path(dev, hid->phys, sizeof(hid->phys));
1153 strlcat(hid->phys, "/input", sizeof(hid->phys));

Found by Linux Driver Verification Project.

Use strlcat instead of strncat.

---

 drivers/media/video/usbvideo/konicawc.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/video/usbvideo/konicawc.c renamed from drivers/media/video/usbvideo/konicawc.c~konicawcc-possible-buffer-overflow-while-use-strncat +1 -1
diff -puN drivers/media/video/usbvideo/konicawc.c~konicawcc-possible-buffer-overflow-while-use-strncat 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) {

_