diff options
author | Luiz Fernando Capitulino <lcapitulino@mandriva.com.br> | 2005-11-28 16:16:05 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-01-04 16:48:35 -0500 |
commit | 487f9c6710e7dff338e59820f6cfaeaaa87cb532 (patch) | |
tree | cf8b5706aa97d8a9143a40658440772863320bd7 /drivers | |
parent | 717f736d937d0e98e964375dac770bfa20f73b72 (diff) |
[PATCH] USB: usbserial: Adds missing checks and bug fix.
Checks if 'port' is NULL before using it in all tty operations, this
can avoid NULL pointer dereferences.
Signed-off-by: Luiz Capitulino <lcapitulino@mandriva.com.br>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/serial/usb-serial.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 12aaf18ff9ea..5bc023c73893 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -188,6 +188,8 @@ static int serial_open (struct tty_struct *tty, struct file * filp) | |||
188 | 188 | ||
189 | portNumber = tty->index - serial->minor; | 189 | portNumber = tty->index - serial->minor; |
190 | port = serial->port[portNumber]; | 190 | port = serial->port[portNumber]; |
191 | if (!port) | ||
192 | return -ENODEV; | ||
191 | 193 | ||
192 | ++port->open_count; | 194 | ++port->open_count; |
193 | 195 | ||
@@ -258,6 +260,9 @@ static int serial_write (struct tty_struct * tty, const unsigned char *buf, int | |||
258 | struct usb_serial_port *port = tty->driver_data; | 260 | struct usb_serial_port *port = tty->driver_data; |
259 | int retval = -EINVAL; | 261 | int retval = -EINVAL; |
260 | 262 | ||
263 | if (!port) | ||
264 | goto exit; | ||
265 | |||
261 | dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count); | 266 | dbg("%s - port %d, %d byte(s)", __FUNCTION__, port->number, count); |
262 | 267 | ||
263 | if (!port->open_count) { | 268 | if (!port->open_count) { |
@@ -277,6 +282,9 @@ static int serial_write_room (struct tty_struct *tty) | |||
277 | struct usb_serial_port *port = tty->driver_data; | 282 | struct usb_serial_port *port = tty->driver_data; |
278 | int retval = -EINVAL; | 283 | int retval = -EINVAL; |
279 | 284 | ||
285 | if (!port) | ||
286 | goto exit; | ||
287 | |||
280 | dbg("%s - port %d", __FUNCTION__, port->number); | 288 | dbg("%s - port %d", __FUNCTION__, port->number); |
281 | 289 | ||
282 | if (!port->open_count) { | 290 | if (!port->open_count) { |
@@ -296,6 +304,9 @@ static int serial_chars_in_buffer (struct tty_struct *tty) | |||
296 | struct usb_serial_port *port = tty->driver_data; | 304 | struct usb_serial_port *port = tty->driver_data; |
297 | int retval = -EINVAL; | 305 | int retval = -EINVAL; |
298 | 306 | ||
307 | if (!port) | ||
308 | goto exit; | ||
309 | |||
299 | dbg("%s = port %d", __FUNCTION__, port->number); | 310 | dbg("%s = port %d", __FUNCTION__, port->number); |
300 | 311 | ||
301 | if (!port->open_count) { | 312 | if (!port->open_count) { |
@@ -314,6 +325,9 @@ static void serial_throttle (struct tty_struct * tty) | |||
314 | { | 325 | { |
315 | struct usb_serial_port *port = tty->driver_data; | 326 | struct usb_serial_port *port = tty->driver_data; |
316 | 327 | ||
328 | if (!port) | ||
329 | return; | ||
330 | |||
317 | dbg("%s - port %d", __FUNCTION__, port->number); | 331 | dbg("%s - port %d", __FUNCTION__, port->number); |
318 | 332 | ||
319 | if (!port->open_count) { | 333 | if (!port->open_count) { |
@@ -330,6 +344,9 @@ static void serial_unthrottle (struct tty_struct * tty) | |||
330 | { | 344 | { |
331 | struct usb_serial_port *port = tty->driver_data; | 345 | struct usb_serial_port *port = tty->driver_data; |
332 | 346 | ||
347 | if (!port) | ||
348 | return; | ||
349 | |||
333 | dbg("%s - port %d", __FUNCTION__, port->number); | 350 | dbg("%s - port %d", __FUNCTION__, port->number); |
334 | 351 | ||
335 | if (!port->open_count) { | 352 | if (!port->open_count) { |
@@ -347,6 +364,9 @@ static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned in | |||
347 | struct usb_serial_port *port = tty->driver_data; | 364 | struct usb_serial_port *port = tty->driver_data; |
348 | int retval = -ENODEV; | 365 | int retval = -ENODEV; |
349 | 366 | ||
367 | if (!port) | ||
368 | goto exit; | ||
369 | |||
350 | dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd); | 370 | dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd); |
351 | 371 | ||
352 | if (!port->open_count) { | 372 | if (!port->open_count) { |
@@ -368,6 +388,9 @@ static void serial_set_termios (struct tty_struct *tty, struct termios * old) | |||
368 | { | 388 | { |
369 | struct usb_serial_port *port = tty->driver_data; | 389 | struct usb_serial_port *port = tty->driver_data; |
370 | 390 | ||
391 | if (!port) | ||
392 | return; | ||
393 | |||
371 | dbg("%s - port %d", __FUNCTION__, port->number); | 394 | dbg("%s - port %d", __FUNCTION__, port->number); |
372 | 395 | ||
373 | if (!port->open_count) { | 396 | if (!port->open_count) { |
@@ -384,6 +407,9 @@ static void serial_break (struct tty_struct *tty, int break_state) | |||
384 | { | 407 | { |
385 | struct usb_serial_port *port = tty->driver_data; | 408 | struct usb_serial_port *port = tty->driver_data; |
386 | 409 | ||
410 | if (!port) | ||
411 | return; | ||
412 | |||
387 | dbg("%s - port %d", __FUNCTION__, port->number); | 413 | dbg("%s - port %d", __FUNCTION__, port->number); |
388 | 414 | ||
389 | if (!port->open_count) { | 415 | if (!port->open_count) { |
@@ -445,6 +471,9 @@ static int serial_tiocmget (struct tty_struct *tty, struct file *file) | |||
445 | { | 471 | { |
446 | struct usb_serial_port *port = tty->driver_data; | 472 | struct usb_serial_port *port = tty->driver_data; |
447 | 473 | ||
474 | if (!port) | ||
475 | goto exit; | ||
476 | |||
448 | dbg("%s - port %d", __FUNCTION__, port->number); | 477 | dbg("%s - port %d", __FUNCTION__, port->number); |
449 | 478 | ||
450 | if (!port->open_count) { | 479 | if (!port->open_count) { |
@@ -464,6 +493,9 @@ static int serial_tiocmset (struct tty_struct *tty, struct file *file, | |||
464 | { | 493 | { |
465 | struct usb_serial_port *port = tty->driver_data; | 494 | struct usb_serial_port *port = tty->driver_data; |
466 | 495 | ||
496 | if (!port) | ||
497 | goto exit; | ||
498 | |||
467 | dbg("%s - port %d", __FUNCTION__, port->number); | 499 | dbg("%s - port %d", __FUNCTION__, port->number); |
468 | 500 | ||
469 | if (!port->open_count) { | 501 | if (!port->open_count) { |