* [PATCH net-next] net/sched: replace strncpy with strscpy
@ 2025-06-17 12:35 Pranav Tyagi
2025-06-18 10:54 ` Simon Horman
0 siblings, 1 reply; 3+ messages in thread
From: Pranav Tyagi @ 2025-06-17 12:35 UTC (permalink / raw)
To: jhs, xiyou.wangcong, jiri
Cc: davem, edumazet, kuba, pabeni, horms, netdev, linux-kernel, skhan,
linux-kernel-mentees, Pranav Tyagi
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));
conf.from_offset = tm->from_offset;
conf.to_offset = tm->to_offset;
conf.from_layer = tm->from_layer;
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net/sched: replace strncpy with strscpy
2025-06-17 12:35 [PATCH net-next] net/sched: replace strncpy with strscpy Pranav Tyagi
@ 2025-06-18 10:54 ` Simon Horman
2025-06-18 14:23 ` Pranav Tyagi
0 siblings, 1 reply; 3+ messages in thread
From: Simon Horman @ 2025-06-18 10:54 UTC (permalink / raw)
To: Pranav Tyagi
Cc: jhs, xiyou.wangcong, jiri, davem, edumazet, kuba, pabeni, netdev,
linux-kernel, skhan, linux-kernel-mentees
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net/sched: replace strncpy with strscpy
2025-06-18 10:54 ` Simon Horman
@ 2025-06-18 14:23 ` Pranav Tyagi
0 siblings, 0 replies; 3+ messages in thread
From: Pranav Tyagi @ 2025-06-18 14:23 UTC (permalink / raw)
To: Simon Horman
Cc: jhs, xiyou.wangcong, jiri, davem, edumazet, kuba, pabeni, netdev,
linux-kernel, skhan, linux-kernel-mentees
On Wed, Jun 18, 2025 at 4:24 PM Simon Horman <horms@kernel.org> wrote:
>
> 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
Hi,
Thanks for the feedback. I'll update the patch accordingly
and send a v2 for the same.
Regards
Pranav Tyagi
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-06-18 14:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-17 12:35 [PATCH net-next] net/sched: replace strncpy with strscpy Pranav Tyagi
2025-06-18 10:54 ` Simon Horman
2025-06-18 14:23 ` Pranav Tyagi
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).