mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Strakh <strakh@ispras.ru>
To: Simon Evans <spse@secret.org.uk>,
	Mauro Carvalho Chehab <mchehab@infradead.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] konicawc.c: possible buffer overflow while use strncat.
Date: Wed, 7 Oct 2009 15:56:58 +0000	[thread overview]
Message-ID: <200910071556.59139.strakh@ispras.ru> (raw)

	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.

Signed-off-by:Alexander Strakh <strakh@ispras.ru>

---
diff --git a/./a/drivers/media/video/usbvideo/konicawc.c 
b/./b/drivers/media/video/usbvideo/konicawc.c
index 31d57f2..a0addcb 100644
--- a/./a/drivers/media/video/usbvideo/konicawc.c
+++ b/./b/drivers/media/video/usbvideo/konicawc.c
@@ -225,7 +225,7 @@ static void konicawc_register_input(struct konicawc *cam, 
struct usb_device *dev
 	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) {


                 reply	other threads:[~2009-10-07 11:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200910071556.59139.strakh@ispras.ru \
    --to=strakh@ispras.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=spse@secret.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome