netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Pranav Tyagi <pranav.tyagi03@gmail.com>
Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, skhan@linuxfoundation.org,
	linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH net-next] net/sched: replace strncpy with strscpy
Date: Wed, 18 Jun 2025 11:54:13 +0100	[thread overview]
Message-ID: <20250618105413.GF1699@horms.kernel.org> (raw)
In-Reply-To: <20250617123531.23523-1-pranav.tyagi03@gmail.com>

On Tue, Jun 17, 2025 at 06:05:31PM +0530, Pranav Tyagi wrote:
> Replace the deprecated strncpy() with strscpy() as the destination
> buffer should be NUL-terminated and does not require any trailing
> NUL-padding. Also, since NUL-termination is guaranteed,
> use sizeof(conf.algo) in place of sizeof(conf.algo) - 1
> as the size parameter.
> 
> Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
> ---
>  net/sched/em_text.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/sched/em_text.c b/net/sched/em_text.c
> index 420c66203b17..1d0debfd62e5 100644
> --- a/net/sched/em_text.c
> +++ b/net/sched/em_text.c
> @@ -108,7 +108,7 @@ static int em_text_dump(struct sk_buff *skb, struct tcf_ematch *m)
>  	struct text_match *tm = EM_TEXT_PRIV(m);
>  	struct tcf_em_text conf;
>  
> -	strncpy(conf.algo, tm->config->ops->name, sizeof(conf.algo) - 1);
> +	strscpy(conf.algo, tm->config->ops->name, sizeof(conf.algo));

Hi Pranav,

Because the destination is an array I think we can use the two-argument
version of strscpy() here.

	strscpy(conf.algo, tm->config->ops->name);

>  	conf.from_offset = tm->from_offset;
>  	conf.to_offset = tm->to_offset;
>  	conf.from_layer = tm->from_layer;

-- 
pw-bot: changes-requested

  reply	other threads:[~2025-06-18 10:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-17 12:35 [PATCH net-next] net/sched: replace strncpy with strscpy Pranav Tyagi
2025-06-18 10:54 ` Simon Horman [this message]
2025-06-18 14:23   ` Pranav Tyagi

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=20250618105413.GF1699@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-kernel-mentees@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pranav.tyagi03@gmail.com \
    --cc=skhan@linuxfoundation.org \
    --cc=xiyou.wangcong@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).