Skip to contentSkip to conversation

tcm_vhost: strlen() doesn't count the terminator

PATCH Applied Dan Carpenter 2 participants 2 messages Jul 12, 2012

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

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

We do snprintf() from "page" to a buffer with TCM_VHOST_NAMELEN characters so the current code will silently truncate the last character.

drivers/vhost/tcm_vhost.c +1 -1
index d217bed..57d39c5 100644
@@ -1254,7 +1254,7 @@ static ssize_t tcm_vhost_tpg_store_nexus(
 	 * the fabric protocol_id set in tcm_vhost_make_tport(), and call
 	 * tcm_vhost_make_nexus().
 	 */
-	if (strlen(page) > TCM_VHOST_NAMELEN) {
+	if (strlen(page) >= TCM_VHOST_NAMELEN) {
 		pr_err("Emulated NAA Sas Address: %s, exceeds"
 				" max: %d\n", page, TCM_VHOST_NAMELEN);
 		return -EINVAL;
#1 lore raw
Quoted 11 lines · Dan Carpenter

We do snprintf() from "page" to a buffer with TCM_VHOST_NAMELEN characters so the current code will silently truncate the last character.

drivers/vhost/tcm_vhost.c +0 -0
index d217bed..57d39c5 100644

drivers/vhost/tcm_vhost.c static ssize_t tcm_vhost_tpg_store_nexus( · line 1260

Quoted 8 lines
drivers/vhost/tcm_vhost.c +1 -1
@@ -1254,7 +1254,7 @@ static ssize_t tcm_vhost_tpg_store_nexus(
 	 * the fabric protocol_id set in tcm_vhost_make_tport(), and call
 	 * tcm_vhost_make_nexus().
 	 */
-	if (strlen(page) > TCM_VHOST_NAMELEN) {
+	if (strlen(page) >= TCM_VHOST_NAMELEN) {
 		pr_err("Emulated NAA Sas Address: %s, exceeds"
 				" max: %d\n", page, TCM_VHOST_NAMELEN);
 		return -EINVAL;

Also applied. Thanks!