public inbox for kernel-janitors@vger.kernel.org
 help / color / mirror / Atom feed
* [patch 2/2] USB: keyspan: add a sanity test on "len"
@ 2013-04-04  6:35 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2013-04-04  6:35 UTC (permalink / raw)
  To: kernel-janitors

"len" comes from the USB transfer and it's probably correct.  The thing
is that we already have similar checks like:

	if (data[i] >= serial->num_ports) {

So adding a sanity test here matches the rest of the code and is a good
idea.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index c773ac7..84b5028 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -727,14 +727,15 @@ static void usa49wg_indat_callback(struct urb *urb)
 		if ((data[i] & 0x80) = 0) {
 			/* no error on any byte */
 			i++;
-			for (x = 1; x < len ; ++x)
+			for (x = 1; x < len && i < urb->actual_length; ++x)
 				tty_insert_flip_char(&port->port,
 						data[i++], 0);
 		} else {
 			/*
 			 * some bytes had errors, every byte has status
 			 */
-			for (x = 0; x + 1 < len; x += 2) {
+			for (x = 0; x + 1 < len &&
+				    i + 1 < urb->actual_length; x += 2) {
 				int stat = data[i], flag = 0;
 				if (stat & RXERROR_OVERRUN)
 					flag |= TTY_OVERRUN;

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2013-04-04  6:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-04  6:35 [patch 2/2] USB: keyspan: add a sanity test on "len" Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox