From: Dan Carpenter <dan.carpenter@linaro.org>
To: Hongbo Li <lihongbo22@huawei.com>
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, dsahern@kernel.org, ralf@linux-mips.org,
jmaloy@redhat.com, ying.xue@windriver.com,
netdev@vger.kernel.org, linux-hams@vger.kernel.org,
netfilter-devel@vger.kernel.org
Subject: Re: [PATCH net-next 1/6] net: prefer strscpy over strcpy
Date: Tue, 27 Aug 2024 15:30:26 +0300 [thread overview]
Message-ID: <a60d4c8f-409e-4149-9eae-64bb3ea2e6bf@stanley.mountain> (raw)
In-Reply-To: <20240827113527.4019856-2-lihongbo22@huawei.com>
On Tue, Aug 27, 2024 at 07:35:22PM +0800, Hongbo Li wrote:
> The deprecated helper strcpy() performs no bounds checking on the
> destination buffer. This could result in linear overflows beyond
> the end of the buffer, leading to all kinds of misbehaviors.
> The safe replacement is strscpy() [1].
>
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
>
> Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
> ---
> net/core/dev.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 0d0b983a6c21..f5e0a0d801fd 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -11121,7 +11121,7 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
> if (!dev->ethtool)
> goto free_all;
>
> - strcpy(dev->name, name);
> + strscpy(dev->name, name, sizeof(dev->name));
You can just do:
strscpy(dev->name, name);
I prefer this format because it ensures that dev->name is an array and not a
pointer. Also shorter.
regards,
dan carpenter
next prev parent reply other threads:[~2024-08-27 12:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-27 11:35 [PATCH net-next 0/6] replace deprecated strcpy with strscpy Hongbo Li
2024-08-27 11:35 ` [PATCH net-next 1/6] net: prefer strscpy over strcpy Hongbo Li
2024-08-27 12:30 ` Dan Carpenter [this message]
2024-08-28 7:43 ` Hongbo Li
2024-08-28 8:54 ` Dan Carpenter
2024-08-27 11:35 ` [PATCH net-next 2/6] net/ipv6: replace deprecated strcpy with strscpy Hongbo Li
2024-08-27 11:35 ` [PATCH net-next 3/6] net/netrom: prefer strscpy over strcpy Hongbo Li
2024-08-27 11:35 ` [PATCH net-next 4/6] net/netfilter: replace deprecated strcpy with strscpy Hongbo Li
2024-08-27 11:35 ` [PATCH net-next 5/6] net/tipc: " Hongbo Li
2024-08-27 11:35 ` [PATCH net-next 6/6] net/ipv4: net: prefer strscpy over strcpy Hongbo Li
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=a60d4c8f-409e-4149-9eae-64bb3ea2e6bf@stanley.mountain \
--to=dan.carpenter@linaro.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=jmaloy@redhat.com \
--cc=kuba@kernel.org \
--cc=lihongbo22@huawei.com \
--cc=linux-hams@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ralf@linux-mips.org \
--cc=ying.xue@windriver.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