Linux NFS development
 help / color / mirror / Atom feed
From: Jeff Layton <jeff.layton@primarydata.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: "J. Bruce Fields" <bfields@fieldses.org>,
	Chuck Lever <chuck.lever@oracle.com>,
	linux-nfs@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] nfsd: minor off by one checks in __write_versions()
Date: Thu, 27 Nov 2014 20:17:53 -0500	[thread overview]
Message-ID: <20141127201753.26753f9d@tlielax.poochiereds.net> (raw)
In-Reply-To: <20141127155854.GB21914@mwanda>

On Thu, 27 Nov 2014 18:58:54 +0300
Dan Carpenter <dan.carpenter@oracle.com> wrote:

> My static checker complains that if "len == remaining" then it means we
> have truncated the last character off the version string.
> 
> The intent of the code is that we print as many versions as we can
> without truncating a version.  Then we put a newline at the end.  If the
> newline can't fit we return -EINVAL.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
> index 9506ea5..19ace74 100644
> --- a/fs/nfsd/nfsctl.c
> +++ b/fs/nfsd/nfsctl.c
> @@ -608,7 +608,7 @@ static ssize_t __write_versions(struct file *file, char *buf, size_t size)
>  				       num);
>  			sep = " ";
>  
> -			if (len > remaining)
> +			if (len >= remaining)
>  				break;
>  			remaining -= len;
>  			buf += len;
> @@ -623,7 +623,7 @@ static ssize_t __write_versions(struct file *file, char *buf, size_t size)
>  						'+' : '-',
>  					minor);
>  
> -			if (len > remaining)
> +			if (len >= remaining)
>  				break;
>  			remaining -= len;
>  			buf += len;
> @@ -631,7 +631,7 @@ static ssize_t __write_versions(struct file *file, char *buf, size_t size)
>  		}
>  
>  	len = snprintf(buf, remaining, "\n");
> -	if (len > remaining)
> +	if (len >= remaining)
>  		return -EINVAL;
>  	return tlen + len;
>  }
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

Looks correct. Good catch.

Reviewed-by: Jeff Layton <jlayton@primarydata.com>

      reply	other threads:[~2014-11-28  1:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-27 15:58 [patch] nfsd: minor off by one checks in __write_versions() Dan Carpenter
2014-11-28  1:17 ` Jeff Layton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141127201753.26753f9d@tlielax.poochiereds.net \
    --to=jeff.layton@primarydata.com \
    --cc=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox