OSDN Git Service

USB: yurex: Check for truncation in yurex_read()
authorBen Hutchings <ben.hutchings@codethink.co.uk>
Wed, 15 Aug 2018 20:45:37 +0000 (21:45 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Oct 2018 06:56:00 +0000 (08:56 +0200)
commit1d44f7f5bc07127743e9d4a4f968bcbaf3b95ee9
treeae5e523920edebe073dd63fc7d5bd54d7918e257
parente6ecfa261ae6f4bdfe5a431c7ca8d623335827d2
USB: yurex: Check for truncation in yurex_read()

[ Upstream commit 14427b86837a4baf1c121934c6599bdb67dfa9fc ]

snprintf() always returns the full length of the string it could have
printed, even if it was truncated because the buffer was too small.
So in case the counter value is truncated, we will over-read from
in_buffer and over-write to the caller's buffer.

I don't think it's actually possible for this to happen, but in case
truncation occurs, WARN and return -EIO.

Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/misc/yurex.c