All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] SUNRPC: Replace strlcat() with snprintf() in rpc_sockaddr2uaddr()
@ 2026-06-27  5:11 Ian Bridges
  0 siblings, 0 replies; only message in thread
From: Ian Bridges @ 2026-06-27  5:11 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker; +Cc: linux-nfs, linux-kernel, linux-hardening

In preparation for removing the deprecated strlcat() API[1], replace the
snprintf()/strlcat() pair in rpc_sockaddr2uaddr() with a single snprintf()
that appends the port suffix directly to the address buffer.

rpc_ntop4() and rpc_ntop6_noscopeid() leave a NUL-terminated presentation
address in addrbuf; the port is then formatted as ".p1.p2" and appended.
Writing that suffix at addrbuf + strlen(addrbuf) with snprintf() yields the
same universal address string as the separate portbuf/strlcat() step it
replaces, so the intermediate portbuf is no longer needed.

snprintf() returns the length it would have written excluding the NUL, so
comparing it against the remaining buffer space preserves the existing
truncation check that returns NULL.

Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Ian Bridges <icb@fastmail.org>
---
 net/sunrpc/addr.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/net/sunrpc/addr.c b/net/sunrpc/addr.c
index 97ff11973c49..c164ea214e6a 100644
--- a/net/sunrpc/addr.c
+++ b/net/sunrpc/addr.c
@@ -264,9 +264,9 @@ EXPORT_SYMBOL_GPL(rpc_pton);
  */
 char *rpc_sockaddr2uaddr(const struct sockaddr *sap, gfp_t gfp_flags)
 {
-	char portbuf[RPCBIND_MAXUADDRPLEN];
 	char addrbuf[RPCBIND_MAXUADDRLEN];
 	unsigned short port;
+	size_t len, avail;
 
 	switch (sap->sa_family) {
 	case AF_INET:
@@ -283,11 +283,10 @@ char *rpc_sockaddr2uaddr(const struct sockaddr *sap, gfp_t gfp_flags)
 		return NULL;
 	}
 
-	if (snprintf(portbuf, sizeof(portbuf),
-		     ".%u.%u", port >> 8, port & 0xff) >= (int)sizeof(portbuf))
-		return NULL;
-
-	if (strlcat(addrbuf, portbuf, sizeof(addrbuf)) >= sizeof(addrbuf))
+	len = strlen(addrbuf);
+	avail = sizeof(addrbuf) - len;
+	if (snprintf(addrbuf + len, avail, ".%u.%u",
+		     port >> 8, port & 0xff) >= avail)
 		return NULL;
 
 	return kstrdup(addrbuf, gfp_flags);
-- 
2.47.3


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-06-27  5:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-27  5:11 [PATCH] SUNRPC: Replace strlcat() with snprintf() in rpc_sockaddr2uaddr() Ian Bridges

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.