netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Shi Hao <i.shihao.999@gmail.com>
Cc: pavan.chebbi@broadcom.com, mchan@broadcom.com,
	andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
	kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] net: ethernet: broadcom: replace strcpy with strscpy
Date: Thu, 13 Nov 2025 19:22:18 +0000	[thread overview]
Message-ID: <20251113192218.3c17dabc@pumpkin> (raw)
In-Reply-To: <20251113082517.49007-1-i.shihao.999@gmail.com>

On Thu, 13 Nov 2025 13:55:17 +0530
Shi Hao <i.shihao.999@gmail.com> wrote:

> Replace strcpy function calls with strscpy to ensure bounds checking
> in the destination buffer, preventing buffer overflows and improving
> security. This change aligns with current kernel coding guidelines
> and best practices.
> 
...
> -			strcpy(tp->board_part_number, "BCM5717");
> +			strscpy(tp->board_part_number, "BCM5717", TG3_BPN_SIZE);

No one really knows that TG3_BPN_SIZE is in any way related to the destination.
So this doesn't actually make the code that much better at all.

Since tp->board_part_number is an array and "BCM5717" a constant I suspect
there is already a compile-time check that the string fits.
The strcpy() will also be converted to a memcpy().

So all, in all, this makes the code worse on several fronts.

	David

  reply	other threads:[~2025-11-13 19:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-13  8:25 [PATCH] net: ethernet: broadcom: replace strcpy with strscpy Shi Hao
2025-11-13 19:22 ` David Laight [this message]
2025-11-14  9:07   ` ShiHao

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=20251113192218.3c17dabc@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=i.shihao.999@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchan@broadcom.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pavan.chebbi@broadcom.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).