Skip to contentSkip to conversation

target: strlen() doesn't count the terminator

PATCH In review Dan Carpenter 2 participants 2 messages Oct 2, 2012

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

PATCH 2/2 target: strlen() doesn't count the terminator

We need to take the terminator into consideration here or the last character gets silently truncated away later.

drivers/usb/gadget/tcm_usb_gadget.c +1 -1
index 1ad4a69..97e68b3 100644
@@ -1812,7 +1812,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 10 lines · Dan Carpenter

We need to take the terminator into consideration here or the last character gets silently truncated away later.

drivers/usb/gadget/tcm_usb_gadget.c +0 -0
index 1ad4a69..97e68b3 100644

drivers/usb/gadget/tcm_usb_gadget.c static ssize_t tcm_usbg_tpg_store_nexus(

Quoted 9 lines
drivers/usb/gadget/tcm_usb_gadget.c +1 -2
@@ -1812,7 +1812,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;
--

Also applied to for-next.

Thanks Dan !

--nab