usbip: tools: fix atoi() on non-null terminated string
authorColin Ian King <colin.king@canonical.com>
Tue, 16 Oct 2018 18:03:43 +0000 (19:03 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 1 Dec 2019 08:16:38 +0000 (09:16 +0100)
commit1f7f2a0666a31d824e98e54220bba96f5ac2f4ee
tree69308ac4684ad2fcb4284a9d030094e76fa8eaac
parent283d9618e22b7ff43ac6fc16c35f3c4d24fbb733
usbip: tools: fix atoi() on non-null terminated string

[ Upstream commit e325808c0051b16729ffd472ff887c6cae5c6317 ]

Currently the call to atoi is being passed a single char string
that is not null terminated, so there is a potential read overrun
along the stack when parsing for an integer value.  Fix this by
instead using a 2 char string that is initialized to all zeros
to ensure that a 1 char read into the string is always terminated
with a \0.

Detected by cppcheck:
"Invalid atoi() argument nr 1. A nul-terminated string is required."

Fixes: 3391ba0e2792 ("usbip: tools: Extract generic code to be shared with vudc backend")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/usb/usbip/libsrc/usbip_host_common.c