diff options
author | Colin Ian King <colin.king@canonical.com> | 2018-10-16 14:03:43 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-10-18 13:44:39 -0400 |
commit | e325808c0051b16729ffd472ff887c6cae5c6317 (patch) | |
tree | 92e61ed3a5bf24684bf64f3746b03c914577eeac /tools | |
parent | 090158555ff8d194a98616034100b16697dd80d0 (diff) |
usbip: tools: fix atoi() on non-null terminated string
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>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/usb/usbip/libsrc/usbip_host_common.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c b/tools/usb/usbip/libsrc/usbip_host_common.c index dc93fadbee96..d79c7581b175 100644 --- a/tools/usb/usbip/libsrc/usbip_host_common.c +++ b/tools/usb/usbip/libsrc/usbip_host_common.c | |||
@@ -43,7 +43,7 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev) | |||
43 | int size; | 43 | int size; |
44 | int fd; | 44 | int fd; |
45 | int length; | 45 | int length; |
46 | char status; | 46 | char status[2] = { 0 }; |
47 | int value = 0; | 47 | int value = 0; |
48 | 48 | ||
49 | size = snprintf(status_attr_path, sizeof(status_attr_path), | 49 | size = snprintf(status_attr_path, sizeof(status_attr_path), |
@@ -61,14 +61,14 @@ static int32_t read_attr_usbip_status(struct usbip_usb_device *udev) | |||
61 | return -1; | 61 | return -1; |
62 | } | 62 | } |
63 | 63 | ||
64 | length = read(fd, &status, 1); | 64 | length = read(fd, status, 1); |
65 | if (length < 0) { | 65 | if (length < 0) { |
66 | err("error reading attribute %s", status_attr_path); | 66 | err("error reading attribute %s", status_attr_path); |
67 | close(fd); | 67 | close(fd); |
68 | return -1; | 68 | return -1; |
69 | } | 69 | } |
70 | 70 | ||
71 | value = atoi(&status); | 71 | value = atoi(status); |
72 | 72 | ||
73 | return value; | 73 | return value; |
74 | } | 74 | } |