Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: sunrpc: Fix an off by one in rpc_sockaddr2uaddr()

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>

authored by

Christophe JAILLET and committed by
Trond Myklebust
d6f4de70 3f7edeac

+2 -2
+2 -2
net/sunrpc/addr.c
··· 284 284 } 285 285 286 286 if (snprintf(portbuf, sizeof(portbuf), 287 - ".%u.%u", port >> 8, port & 0xff) > (int)sizeof(portbuf)) 287 + ".%u.%u", port >> 8, port & 0xff) >= (int)sizeof(portbuf)) 288 288 return NULL; 289 289 290 - if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) > sizeof(addrbuf)) 290 + if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) >= sizeof(addrbuf)) 291 291 return NULL; 292 292 293 293 return kstrdup(addrbuf, gfp_flags);