Skip to content

Commit

Permalink
USB: serial: keyspan_pda: fix receive sanity checks
Browse files Browse the repository at this point in the history
Make sure to check for short transfers before parsing the receive buffer
to avoid acting on stale data.

Fixes: 1da177e ("Linux-2.6.12-rc2")
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
  • Loading branch information
jhovold committed Jan 31, 2017
1 parent 1b0aed2 commit c528fcb
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions drivers/usb/serial/keyspan_pda.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static void keyspan_pda_rx_interrupt(struct urb *urb)
{
struct usb_serial_port *port = urb->context;
unsigned char *data = urb->transfer_buffer;
unsigned int len = urb->actual_length;
int retval;
int status = urb->status;
struct keyspan_pda_private *priv;
Expand All @@ -159,18 +160,26 @@ static void keyspan_pda_rx_interrupt(struct urb *urb)
goto exit;
}

if (len < 1) {
dev_warn(&port->dev, "short message received\n");
goto exit;
}

/* see if the message is data or a status interrupt */
switch (data[0]) {
case 0:
/* rest of message is rx data */
if (urb->actual_length) {
tty_insert_flip_string(&port->port, data + 1,
urb->actual_length - 1);
tty_flip_buffer_push(&port->port);
}
if (len < 2)
break;
tty_insert_flip_string(&port->port, data + 1, len - 1);
tty_flip_buffer_push(&port->port);
break;
case 1:
/* status interrupt */
if (len < 3) {
dev_warn(&port->dev, "short interrupt message received\n");
break;
}
dev_dbg(&port->dev, "rx int, d1=%d, d2=%d\n", data[1], data[2]);
switch (data[1]) {
case 1: /* modemline change */
Expand Down

0 comments on commit c528fcb

Please sign in to comment.