Skip to contentSkip to conversation

target: usb-gadget: silently truncating the last character

PATCH Applied Dan Carpenter 2 participants 2 messages Apr 17, 2012 – Apr 18, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 target: usb-gadget: silently truncating the last character

strlen() doesn't count the NULL character, so this test is off by one. The result is that sometimes it can silently chop off the last character of the name.

drivers/target/usb-gadget/usb_gadget.c +1 -1
index f5e7531..ba62bef 100644
@@ -1830,7 +1830,7 @@ static ssize_t tcm_usbg_tpg_store_nexus(
 		ret = tcm_usbg_drop_nexus(tpg);
 		return (!ret) ? count : ret;
 	}
-	if (strlen(page) > USBG_NAMELEN) {
+	if (strlen(page) >= USBG_NAMELEN) {
 		pr_err("Emulated NAA Sas Address: %s, exceeds"
 				" max: %d\n", page, USBG_NAMELEN);
 		return -EINVAL;
#1 lore raw
Quoted 11 lines · Dan Carpenter

strlen() doesn't count the NULL character, so this test is off by one. The result is that sometimes it can silently chop off the last character of the name.

drivers/target/usb-gadget/usb_gadget.c +0 -0
index f5e7531..ba62bef 100644

drivers/target/usb-gadget/usb_gadget.c static ssize_t tcm_usbg_tpg_store_nexus(

Quoted 9 lines
drivers/target/usb-gadget/usb_gadget.c +1 -2
@@ -1830,7 +1830,7 @@ static ssize_t tcm_usbg_tpg_store_nexus(
 		ret = tcm_usbg_drop_nexus(tpg);
 		return (!ret) ? count : ret;
 	}
-	if (strlen(page) > USBG_NAMELEN) {
+	if (strlen(page) >= USBG_NAMELEN) {
 		pr_err("Emulated NAA Sas Address: %s, exceeds"
 				" max: %d\n", page, USBG_NAMELEN);
 		return -EINVAL;
--

Applied to lio-core. Thanks!

--nab