Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by Hangbin Liu
Fri, 27 Nov 2026 07:05
Re: [PATCH iproute2] names: terminate the name returned by id_to_name()
Author: Hangbin Liu
Date: Fri, 27 Nov 2026 07:05
Date: Fri, 27 Nov 2026 07:05
33 lines
9004 bytes
9004 bytes
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>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads