Re: [PATCH v2 1/2] usbip: Fix-format-overflow

From: Krzysztof Opasiak
Date: Wed Feb 22 2017 - 00:50:05 EST


Hi,

W dniu 2017-02-21 o 18:57, Jonathan Dieter pisze:
The usbip userspace tools call sprintf()/snprintf() and don't check for
the return value which can lead the paths to overflow, truncating the
final file in the path.

More urgently, GCC 7 now warns that these aren't checked with
-Wformat-overflow, and with -Werror enabled in configure.ac, that makes
these tools unbuildable.

This patch fixes these problems by replacing sprintf() with snprintf() in
one place and adding checks for the return value of snprintf().

Reviewed-by: Peter Senna Tschudin <peter.senna@xxxxxxxxx>
Signed-off-by: Jonathan Dieter <jdieter@xxxxxxxxx>
---
tools/usb/usbip/libsrc/usbip_common.c | 8 +++++++-
tools/usb/usbip/libsrc/usbip_host_common.c | 25 ++++++++++++++++++++-----
2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/tools/usb/usbip/libsrc/usbip_common.c b/tools/usb/usbip/libsrc/usbip_common.c
index ac73710..01dd4b2 100644
--- a/tools/usb/usbip/libsrc/usbip_common.c
+++ b/tools/usb/usbip/libsrc/usbip_common.c
@@ -215,9 +215,15 @@ int read_usb_interface(struct usbip_usb_device *udev, int i,
struct usbip_usb_interface *uinf)
{
char busid[SYSFS_BUS_ID_SIZE];
+ unsigned int size;

I'm not really convinced to use unsigned here. snprintf() is declared to return signed integer so we should assume that some of its implementation may return negative error code. Any rationale to this instead of just doing a cast for comparsion but signed value to print error?

Best regards
--
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics