From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: dsahern@kernel.org, Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2] names: terminate the name returned by id_to_name()
Date: Wed, 25 Nov 2026 08:47:21 -0800 [thread overview]
Message-ID: <20261125164721.1942828-1-stephen@networkplumber.org> (raw)
strncpy() does not terminate when the source is as long as the limit,
and the tc class name from tc_cls may be up to NAME_MAX_LEN while the
caller's buffer is IDNAME_MAX. A name of 256 characters or more filled
the buffer with no room for the NUL, so the snprintf() that formats it
read past the end.
Use strlcpy(), which always terminates.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/names.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/names.c b/lib/names.c
index 4ecae92b..697942d2 100644
--- a/lib/names.c
+++ b/lib/names.c
@@ -142,7 +142,7 @@ char *id_to_name(struct db_names *db, int id, char *name)
entry = entry->next;
if (entry) {
- strncpy(name, entry->name, IDNAME_MAX);
+ strlcpy(name, entry->name, IDNAME_MAX);
return name;
}
--
2.53.0
reply other threads:[~2026-11-25 16:47 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=20261125164721.1942828-1-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dsahern@kernel.org \
--cc=netdev@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox