NFS: Fix an off by one in root_nfs_cat()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 18 Feb 2024 21:16:53 +0000 (22:16 +0100)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Sat, 9 Mar 2024 14:14:51 +0000 (09:14 -0500)
The intent is to check if 'dest' is truncated or not. So, >= should be
used instead of >, because strlcat() returns the length of 'dest' and 'src'
excluding the trailing NULL.

Fixes: 56463e50d1fc ("NFS: Use super.c for NFSROOT mount option parsing")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/nfsroot.c

index 7600100ba26f02884812653db5d0231c4e63d0d2..432612d22437423ce5e0d38768c73de47f500074 100644 (file)
@@ -175,10 +175,10 @@ static int __init root_nfs_cat(char *dest, const char *src,
        size_t len = strlen(dest);
 
        if (len && dest[len - 1] != ',')
-               if (strlcat(dest, ",", destlen) > destlen)
+               if (strlcat(dest, ",", destlen) >= destlen)
                        return -1;
 
-       if (strlcat(dest, src, destlen) > destlen)
+       if (strlcat(dest, src, destlen) >= destlen)
                return -1;
        return 0;
 }