Skip to contentSkip to conversation

usbip:vhci_sysfs.c: check return value of sscanf

PATCH In review John de la Garza 2 participants 2 messages Mar 6, 2014 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usbip:vhci_sysfs.c: check return value of sscanf

Added code to check return value of sscanf.

---
 drivers/staging/usbip/vhci_sysfs.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/staging/usbip/vhci_sysfs.c +4 -2
index 03e6edf..82dd49f 100644
@@ -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);
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · John de la Garza

Added code to check return value of sscanf.

---
  drivers/staging/usbip/vhci_sysfs.c |    6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/staging/usbip/vhci_sysfs.c +2 -1
index 03e6edf..82dd49f 100644
@@ -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) {

drivers/staging/usbip/vhci_sysfs.c static ssize_t store_attach(struct device *dev, struct device_attribute *attr, · line 190

Quoted 9 lines
drivers/staging/usbip/vhci_sysfs.c +2 -1
@@ -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.

-- Shuah

Signature · 4 lines
Shuah Khan
Senior Linux Kernel Developer - Open Source Group
Samsung Research America(Silicon Valley)
[email protected] | (970) 672-0658