* [PATCH iproute2] names: terminate the name returned by id_to_name()
@ 2026-11-25 16:47 Stephen Hemminger
2026-11-27 7:05 ` Hangbin Liu
0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread
* Re: [PATCH iproute2] names: terminate the name returned by id_to_name()
2026-11-25 16:47 [PATCH iproute2] names: terminate the name returned by id_to_name() Stephen Hemminger
@ 2026-11-27 7:05 ` Hangbin Liu
0 siblings, 0 replies; 2+ messages in thread
From: Hangbin Liu @ 2026-11-27 7:05 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev, dsahern
On Wed, Nov 25, 2026 at 08:47:21AM -0800, Stephen Hemminger wrote:
> 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
>
Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 7:05 UTC | newest]
Thread overview: 2+ messages (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
2026-11-27 7:05 ` Hangbin Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox