nfsd: minor off by one checks in __write_versions()
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 27 Nov 2014 15:58:54 +0000 (18:58 +0300)
committerJ. Bruce Fields <bfields@redhat.com>
Mon, 1 Dec 2014 19:45:28 +0000 (12:45 -0700)
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>
fs/nfsd/nfsctl.c

index ca73ca79a0ee40998a7b0a8d7afc5c81eb2440ba..0079b28270e9544e4bbe8d5152448626485ef68b 100644 (file)
@@ -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;
@@ -621,7 +621,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;
@@ -629,7 +629,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;
 }