Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1585940

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

From Krzysztof Opasiak <k.opasiak@samsung.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2 1/2] usbip: Fix-format-overflow
Date 2017-02-22 07:00 +0100
Message-ID <tdy81-5ig-3@gated-at.bofh.it> (permalink)
References <tdmTg-5SM-25@gated-at.bofh.it> <tdy81-5ig-5@gated-at.bofh.it> <tdmTg-5SM-27@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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@gmail.com>
> Signed-off-by: Jonathan Dieter <jdieter@lesbg.com>
> ---
>  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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 1/2] usbip: Fix-format-overflow Jonathan Dieter <jdieter@lesbg.com> - 2017-02-21 19:00 +0100
  Re: [PATCH v2 1/2] usbip: Fix-format-overflow Krzysztof Opasiak <k.opasiak@samsung.com> - 2017-02-22 07:00 +0100
    [PATCH v3 1/2] usbip: Fix-format-overflow Jonathan Dieter <jdieter@lesbg.com> - 2017-02-22 19:20 +0100
      [PATCH v3 2/2] usbip: Fix implicit fallthrough warning Jonathan Dieter <jdieter@lesbg.com> - 2017-02-22 19:20 +0100
      [PATCH v4 1/2] usbip: Fix-format-overflow Jonathan Dieter <jdieter@lesbg.com> - 2017-02-27 10:00 +0100
        [PATCH v4 2/2] usbip: Fix implicit fallthrough warning Jonathan Dieter <jdieter@lesbg.com> - 2017-02-27 10:00 +0100
    Re: [PATCH v2 1/2] usbip: Fix-format-overflow Jonathan Dieter <jdieter@lesbg.com> - 2017-02-22 19:20 +0100

csiph-web