From: Hangbin Liu <hangbin.liu@linux.dev>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org, dsahern@kernel.org
Subject: Re: [PATCH iproute2] names: terminate the name returned by id_to_name()
Date: Fri, 27 Nov 2026 15:05:16 +0800 [thread overview]
Message-ID: <awkrrM2Tu0tveZMv@fedora> (raw)
In-Reply-To: <20261125164721.1942828-1-stephen@networkplumber.org>
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>
prev parent reply other threads:[~2026-11-27 7:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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=awkrrM2Tu0tveZMv@fedora \
--to=hangbin.liu@linux.dev \
--cc=dsahern@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.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