linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shuah Khan <shuah@kernel.org>
To: Colin King <colin.king@canonical.com>,
	Valentina Manea <valentina.manea.m@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usbip: tools: fix atoi() on non-null terminated string
Date: Thu, 25 Oct 2018 12:49:29 -0600	[thread overview]
Message-ID: <82ed890f-f544-ce88-9509-f4eedafe4a91@kernel.org> (raw)
In-Reply-To: <20181016180343.5620-1-colin.king@canonical.com>

Hi Colin,

On 10/16/2018 12:03 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> 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>
> ---
>  tools/usb/usbip/libsrc/usbip_host_common.c | 6 +++---
>  1 file 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)
>  	int size;
>  	int fd;
>  	int length;
> -	char status;
> +	char status[2] = { 0 }>  	int value = 0;
>  
>  	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)
>  		return -1;
>  	}
>  
> -	length = read(fd, &status, 1);
> +	length = read(fd, status, 1);
>  	if (length < 0) {
>  		err("error reading attribute %s", status_attr_path);
>  		close(fd);
>  		return -1;
>  	}
>  
> -	value = atoi(&status);
> +	value = atoi(status);
>  
>  	return value;
>  }
> 

Thanks for the patch. Looks good to me.

Acked-by: Shuah Khan <shuah@kernel.org>

thanks,
-- Shuah

      reply	other threads:[~2018-10-25 18:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-16 18:03 [PATCH] usbip: tools: fix atoi() on non-null terminated string Colin King
2018-10-25 18:49 ` Shuah Khan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=82ed890f-f544-ce88-9509-f4eedafe4a91@kernel.org \
    --to=shuah@kernel.org \
    --cc=colin.king@canonical.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=valentina.manea.m@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).