All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Georgiana Chelu <georgiana.chelu93@gmail.com>
Cc: outreachy-kernel@googlegroups.com
Subject: Re: [PATCH v2] Staging: rtl8723bs: Check sscanf return value
Date: Wed, 18 Oct 2017 16:03:10 +0200	[thread overview]
Message-ID: <20171018140310.GB5315@kroah.com> (raw)
In-Reply-To: <20171017213911.15653-1-georgiana.chelu93@gmail.com>

On Wed, Oct 18, 2017 at 12:39:11AM +0300, Georgiana Chelu wrote:
> Check the sscanf return value and handle it. The function returns
> the number of items of the argument list successfully filled.
> 
> Issue found by checkpatch.pl.
> WARNING: unchecked sscanf return value
> 
> Signed-off-by: Georgiana Chelu <georgiana.chelu93@gmail.com>
> ---
> 
> Changes in v2:
> * compared the return value of scanf to the right value
> * improved the commit message
> 
>  drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
> index 3fca0c2d4c8d..fe538cc088f0 100644
> --- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
> +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c
> @@ -2356,7 +2356,11 @@ static int rtw_wx_read32(struct net_device *dev,
>  
>  	bytes = 0;
>  	addr = 0;
> -	sscanf(ptmp, "%d,%x", &bytes, &addr);
> +	ret = sscanf(ptmp, "%d,%x", &bytes, &addr);
> +	if (ret != 2) {
> +		ret = -EINVAL;
> +		goto exit;
> +	}

Are you sure that the code requires 2 values here?

>  
>  	switch (bytes) {
>  		case 1:
> @@ -2393,12 +2397,15 @@ static int rtw_wx_write32(struct net_device *dev,
>  	u32 addr;
>  	u32 data32;
>  	u32 bytes;
> +	int ret;
>  
>  
>  	bytes = 0;
>  	addr = 0;
>  	data32 = 0;
> -	sscanf(extra, "%d,%x,%x", &bytes, &addr, &data32);
> +	ret = sscanf(extra, "%d,%x,%x", &bytes, &addr, &data32);
> +	if (ret != 3)
> +		return -EINVAL;

Same here, are you sure that 3 values are required?

thanks,

greg k-h


  reply	other threads:[~2017-10-18 14:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-17 21:39 [PATCH v2] Staging: rtl8723bs: Check sscanf return value Georgiana Chelu
2017-10-18 14:03 ` Greg Kroah-Hartman [this message]
2017-10-21 13:09   ` Georgiana Chelu

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=20171018140310.GB5315@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=georgiana.chelu93@gmail.com \
    --cc=outreachy-kernel@googlegroups.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.