diff mbox

[2/3,-next] tcm_vhost: strlen() doesn't count the terminator

Message ID 20120712144831.GE24202@elgon.mountain (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Carpenter July 12, 2012, 2:48 p.m. UTC
We do snprintf() from "page" to a buffer with TCM_VHOST_NAMELEN
characters so the current code will silently truncate the last
character.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Nicholas A. Bellinger July 12, 2012, 9:48 p.m. UTC | #1
On Thu, 2012-07-12 at 17:48 +0300, Dan Carpenter wrote:
> We do snprintf() from "page" to a buffer with TCM_VHOST_NAMELEN
> characters so the current code will silently truncate the last
> character.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
> index d217bed..57d39c5 100644
> --- a/drivers/vhost/tcm_vhost.c
> +++ b/drivers/vhost/tcm_vhost.c
> @@ -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!

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/vhost/tcm_vhost.c b/drivers/vhost/tcm_vhost.c
index d217bed..57d39c5 100644
--- a/drivers/vhost/tcm_vhost.c
+++ b/drivers/vhost/tcm_vhost.c
@@ -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;