Commit 064da5f6 authored by Alexander Nyberg's avatar Alexander Nyberg Committed by Linus Torvalds

[PATCH] Off by one in drivers/parport/probe.c

This fixes a theoretical bug indicated in:
http://bugme.osdl.org/show_bug.cgi?id=240

It prevents overflow in case the required buffer is larger than the passed
buffer.  This I found to be the minimally intrusive change.
Signed-off-by: default avatarAlexander Nyberg <alexn@dsv.su.se>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 78085a46
...@@ -164,8 +164,16 @@ ssize_t parport_device_id (int devnum, char *buffer, size_t len) ...@@ -164,8 +164,16 @@ ssize_t parport_device_id (int devnum, char *buffer, size_t len)
if (retval != 2) goto end_id; if (retval != 2) goto end_id;
idlen = (length[0] << 8) + length[1] - 2; idlen = (length[0] << 8) + length[1] - 2;
if (idlen < len) /*
* Check if the caller-allocated buffer is large enough
* otherwise bail out or there will be an at least off by one.
*/
if (idlen + 1 < len)
len = idlen; len = idlen;
else {
retval = -EINVAL;
goto out;
}
retval = parport_read (dev->port, buffer, len); retval = parport_read (dev->port, buffer, len);
if (retval != len) if (retval != len)
...@@ -205,11 +213,12 @@ ssize_t parport_device_id (int devnum, char *buffer, size_t len) ...@@ -205,11 +213,12 @@ ssize_t parport_device_id (int devnum, char *buffer, size_t len)
buffer[len] = '\0'; buffer[len] = '\0';
parport_negotiate (dev->port, IEEE1284_MODE_COMPAT); parport_negotiate (dev->port, IEEE1284_MODE_COMPAT);
} }
parport_release (dev);
if (retval > 2) if (retval > 2)
parse_data (dev->port, dev->daisy, buffer); parse_data (dev->port, dev->daisy, buffer);
out:
parport_release (dev);
parport_close (dev); parport_close (dev);
return retval; return retval;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment