* [PATCH] SUNRPC: Replace strlcat() with snprintf() in rpc_sockaddr2uaddr()
@ 2026-06-27 5:11 Ian Bridges
2026-07-29 20:46 ` Ian Bridges
0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread
* Re: [PATCH] SUNRPC: Replace strlcat() with snprintf() in rpc_sockaddr2uaddr()
2026-06-27 5:11 [PATCH] SUNRPC: Replace strlcat() with snprintf() in rpc_sockaddr2uaddr() Ian Bridges
@ 2026-07-29 20:46 ` Ian Bridges
0 siblings, 0 replies; 2+ messages in thread
From: Ian Bridges @ 2026-07-29 20:46 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker; +Cc: linux-nfs, linux-kernel, linux-hardening
On Sat, Jun 27, 2026 at 12:11:41AM -0500, Ian Bridges wrote:
Gentle ping. This patch has had no response since it was posted on
June 27. The code it converts is unchanged on mainline as of this
week, and the patch still applies cleanly. Happy to resend if that
is easier.
Thanks,
Ian
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-29 20:46 UTC | newest]
Thread overview: 2+ messages (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
2026-07-29 20:46 ` 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.