Skip to content

Commit

Permalink
nfsd: minor off by one checks in __write_versions()
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Jeff Layton <jlayton@primarydata.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
  • Loading branch information
Dan Carpenter authored and J. Bruce Fields committed Dec 1, 2014
1 parent 067f96e commit 818f2f5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fs/nfsd/nfsctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,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;
Expand All @@ -621,15 +621,15 @@ 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;
tlen += len;
}

len = snprintf(buf, remaining, "\n");
if (len > remaining)
if (len >= remaining)
return -EINVAL;
return tlen + len;
}
Expand Down

0 comments on commit 818f2f5

Please sign in to comment.