net: sunrpc: Fix an off by one in rpc_sockaddr2uaddr()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Tue, 24 Oct 2023 21:58:20 +0000 (23:58 +0200)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Wed, 28 Feb 2024 21:18:18 +0000 (16:18 -0500)
The intent is to check if the strings' are truncated or not. So, >= should
be used instead of >, because strlcat() and snprintf() return the length of
the output, excluding the trailing NULL.

Fixes: a02d69261134 ("SUNRPC: Provide functions for managing universal addresses")
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>
net/sunrpc/addr.c

index d435bffc6199978500dc9106ee63cad8a158f87e..97ff11973c49377cbff0ad36f4b266cc54b1c045 100644 (file)
@@ -284,10 +284,10 @@ char *rpc_sockaddr2uaddr(const struct sockaddr *sap, gfp_t gfp_flags)
        }
 
        if (snprintf(portbuf, sizeof(portbuf),
-                    ".%u.%u", port >> 8, port & 0xff) > (int)sizeof(portbuf))
+                    ".%u.%u", port >> 8, port & 0xff) >= (int)sizeof(portbuf))
                return NULL;
 
-       if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) > sizeof(addrbuf))
+       if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) >= sizeof(addrbuf))
                return NULL;
 
        return kstrdup(addrbuf, gfp_flags);