public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usbip:vhci_sysfs.c: check return value of sscanf
@ 2014-03-06 18:36 John de la Garza
  2014-03-06 20:23 ` Shuah Khan
  0 siblings, 1 reply; 2+ messages in thread
From: John de la Garza @ 2014-03-06 18:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: gregkh, shuah.kh

Added code to check return value of sscanf.

Signed-off-by: John de la Garza <john@jjdev.com>
---
 drivers/staging/usbip/vhci_sysfs.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/usbip/vhci_sysfs.c b/drivers/staging/usbip/vhci_sysfs.c
index 03e6edf..82dd49f 100644
--- a/drivers/staging/usbip/vhci_sysfs.c
+++ b/drivers/staging/usbip/vhci_sysfs.c
@@ -114,7 +114,8 @@ static ssize_t store_detach(struct device *dev, struct device_attribute *attr,
 	int err;
 	__u32 rhport = 0;
 
-	sscanf(buf, "%u", &rhport);
+	if (sscanf(buf, "%u", &rhport) != 1)
+		return -EINVAL;
 
 	/* check rhport */
 	if (rhport >= VHCI_NPORTS) {
@@ -182,7 +183,8 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
 	 * @devid: unique device identifier in a remote host
 	 * @speed: usb device speed in a remote host
 	 */
-	sscanf(buf, "%u %u %u %u", &rhport, &sockfd, &devid, &speed);
+	if (sscanf(buf, "%u %u %u %u", &rhport, &sockfd, &devid, &speed) != 1)
+		return -EINVAL;
 
 	usbip_dbg_vhci_sysfs("rhport(%u) sockfd(%u) devid(%u) speed(%u)\n",
 			     rhport, sockfd, devid, speed);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] usbip:vhci_sysfs.c: check return value of sscanf
  2014-03-06 18:36 [PATCH] usbip:vhci_sysfs.c: check return value of sscanf John de la Garza
@ 2014-03-06 20:23 ` Shuah Khan
  0 siblings, 0 replies; 2+ messages in thread
From: Shuah Khan @ 2014-03-06 20:23 UTC (permalink / raw)
  To: John de la Garza, linux-kernel; +Cc: gregkh, Shuah Khan

On 03/06/2014 11:36 AM, John de la Garza wrote:
> Added code to check return value of sscanf.
>
> Signed-off-by: John de la Garza <john@jjdev.com>
> ---
>   drivers/staging/usbip/vhci_sysfs.c |    6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/usbip/vhci_sysfs.c b/drivers/staging/usbip/vhci_sysfs.c
> index 03e6edf..82dd49f 100644
> --- a/drivers/staging/usbip/vhci_sysfs.c
> +++ b/drivers/staging/usbip/vhci_sysfs.c
> @@ -114,7 +114,8 @@ static ssize_t store_detach(struct device *dev, struct device_attribute *attr,
>   	int err;
>   	__u32 rhport = 0;
>
> -	sscanf(buf, "%u", &rhport);
> +	if (sscanf(buf, "%u", &rhport) != 1)
> +		return -EINVAL;
>
>   	/* check rhport */
>   	if (rhport >= VHCI_NPORTS) {
> @@ -182,7 +183,8 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
>   	 * @devid: unique device identifier in a remote host
>   	 * @speed: usb device speed in a remote host
>   	 */
> -	sscanf(buf, "%u %u %u %u", &rhport, &sockfd, &devid, &speed);
> +	if (sscanf(buf, "%u %u %u %u", &rhport, &sockfd, &devid, &speed) != 1)
> +		return -EINVAL;
>
>   	usbip_dbg_vhci_sysfs("rhport(%u) sockfd(%u) devid(%u) speed(%u)\n",
>   			     rhport, sockfd, devid, speed);
>

Looks good to me.

Reviewed-by: Shuah Khan <shuah.kh@samsung.com>

-- Shuah

-- 
Shuah Khan
Senior Linux Kernel Developer - Open Source Group
Samsung Research America(Silicon Valley)
shuah.kh@samsung.com | (970) 672-0658

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-03-06 20:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-06 18:36 [PATCH] usbip:vhci_sysfs.c: check return value of sscanf John de la Garza
2014-03-06 20:23 ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox