From: Jakub Kicinski <kuba@kernel.org>
To: Simon Horman <horms@kernel.org>
Cc: Pranav Tyagi <pranav.tyagi03@gmail.com>,
davem@davemloft.net, dsahern@kernel.org, edumazet@google.com,
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:19:27 -0700 [thread overview]
Message-ID: <20250415171927.5108d252@kernel.org> (raw)
In-Reply-To: <20250415163536.GA395307@horms.kernel.org>
On Tue, 15 Apr 2025 17:35:36 +0100 Simon Horman wrote:
> > @@ -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.
Isn't this because strncpy() doesn't nul-terminate, and since this is a
static variable if we use len - 1 we guarantee that there will be a null
byte at the end? If we switch to strscpy we'll make the max string len
1 char shorter.
next prev parent reply other threads:[~2025-04-16 0:19 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
2025-04-16 0:19 ` Jakub Kicinski [this message]
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=20250415171927.5108d252@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@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).