From: Ian Bridges <icb@fastmail.org>
To: Trond Myklebust <trondmy@kernel.org>, Anna Schumaker <anna@kernel.org>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: [PATCH] SUNRPC: Replace strlcat() with snprintf() in rpc_sockaddr2uaddr()
Date: Sat, 27 Jun 2026 00:11:37 -0500 [thread overview]
Message-ID: <aj9bie25tpHnz7_G@dev> (raw)
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
reply other threads:[~2026-06-27 5:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aj9bie25tpHnz7_G@dev \
--to=icb@fastmail.org \
--cc=anna@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=trondmy@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.