Netdev List
 help / color / mirror / Atom feed
* [PATCH iproute2] names: terminate the name returned by id_to_name()
@ 2026-11-25 16:47 Stephen Hemminger
  0 siblings, 0 replies; only message in thread
From: Stephen Hemminger @ 2026-11-25 16:47 UTC (permalink / raw)
  To: netdev; +Cc: dsahern, Stephen Hemminger

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


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

only message in thread, other threads:[~2026-11-25 16:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 16:47 [PATCH iproute2] names: terminate the name returned by id_to_name() Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox