Skip to contentSkip to conversation

usbip:usbip_common.c: check return value of sscanf

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

lore
Share & tools
lore
#0 lore raw

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

Added code to check return value of sscanf.

---
 drivers/staging/usbip/usbip_common.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/usbip/usbip_common.c +2 -1
index 4a2aab1..2a11233 100644
@@ -55,7 +55,8 @@ static ssize_t usbip_debug_store(struct device *dev,
 				 struct device_attribute *attr, const char *buf,
 				 size_t count)
 {
-	sscanf(buf, "%lx", &usbip_debug_flag);
+	if (sscanf(buf, "%lx", &usbip_debug_flag) != 1)
+		return -EINVAL;
 	return count;
 }
 DEVICE_ATTR_RW(usbip_debug);
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 1 line · John de la Garza

Added code to check return value of sscanf.

[]

drivers/staging/usbip/usbip_common.c

Quoted 1 line
drivers/staging/usbip/usbip_common.c +0 -0

[]

drivers/staging/usbip/usbip_common.c static ssize_t usbip_debug_store(struct device *dev, · line 59

Quoted 7 lines
drivers/staging/usbip/usbip_common.c +2 -1
@@ -55,7 +55,8 @@ static ssize_t usbip_debug_store(struct device *dev,
 				 struct device_attribute *attr, const char *buf,
 				 size_t count)
 {
-	sscanf(buf, "%lx", &usbip_debug_flag);
+	if (sscanf(buf, "%lx", &usbip_debug_flag) != 1)
+		return -EINVAL;

Generally, it's probably better to convert these sscanf uses to kstrto<foo>, kstrtoul in this case.