From: Simon Horman <horms@kernel.org>
To: Pranav Tyagi <pranav.tyagi03@gmail.com>
Cc: davem@davemloft.net, dsahern@kernel.org, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, skhan@linuxfoundation.org,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linux.dev
Subject: Re: [PATCH net-next] net: ipconfig: replace strncpy with strscpy
Date: Tue, 15 Apr 2025 17:35:36 +0100 [thread overview]
Message-ID: <20250415163536.GA395307@horms.kernel.org> (raw)
In-Reply-To: <20250412160623.9625-1-pranav.tyagi03@gmail.com>
On Sat, Apr 12, 2025 at 09:36:23PM +0530, Pranav Tyagi wrote:
> Replace the deprecated strncpy() with strscpy() as the destination
> buffer is NUL-terminated and does not require any
> trailing NUL-padding.
>
> Signed-off-by: Pranav Tyagi <pranav.tyagi03@gmail.com>
Thanks,
I agree that strscpy() is the correct choice here for
the reasons you give above.
Reviewed-by: Simon Horman <horms@kernel.org>
> ---
> net/ipv4/ipconfig.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
> index c56b6fe6f0d7..eb9b32214e60 100644
> --- a/net/ipv4/ipconfig.c
> +++ b/net/ipv4/ipconfig.c
> @@ -1690,7 +1690,7 @@ static int __init ic_proto_name(char *name)
> *v = 0;
> if (kstrtou8(client_id, 0, dhcp_client_identifier))
> pr_debug("DHCP: Invalid client identifier type\n");
> - strncpy(dhcp_client_identifier + 1, v + 1, 251);
> + strscpy(dhcp_client_identifier + 1, v + 1, 251);
As an aside, I'm curious to know why the length is 251
rather than 252 (sizeof(dhcp_client_identifier) -1).
But that isn't strictly related to this patch.
> *v = ',';
> }
> return 1;
> --
> 2.49.0
>
next prev parent reply other threads:[~2025-04-15 16:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-12 16:06 [PATCH net-next] net: ipconfig: replace strncpy with strscpy Pranav Tyagi
2025-04-15 16:35 ` Simon Horman [this message]
2025-04-16 0:19 ` Jakub Kicinski
2025-04-16 11:17 ` Simon Horman
2025-04-16 15:01 ` 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=20250415163536.GA395307@horms.kernel.org \
--to=horms@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--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 \
/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).