netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: qlge: Replace strncpy with strscpy
@ 2023-10-05 19:14 Ricardo Lopes
  2023-10-06  6:42 ` Dan Carpenter
  2023-10-06 13:32 ` Greg KH
  0 siblings, 2 replies; 6+ messages in thread
From: Ricardo Lopes @ 2023-10-05 19:14 UTC (permalink / raw)
  To: manishc, GR-Linux-NIC-Dev, coiby.xu, gregkh
  Cc: netdev, linux-staging, linux-kernel

Avoid read overflows and other misbehavior due to missing termination.

Reported by checkpatch:

WARNING: Prefer strscpy, strscpy_pad, or __nonstring over strncpy

Signed-off-by: Ricardo Lopes <ricardoapl.dev@gmail.com>
---
 drivers/staging/qlge/qlge_dbg.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/qlge/qlge_dbg.c b/drivers/staging/qlge/qlge_dbg.c
index c7e865f51..5f08a8492 100644
--- a/drivers/staging/qlge/qlge_dbg.c
+++ b/drivers/staging/qlge/qlge_dbg.c
@@ -696,7 +696,7 @@ static void qlge_build_coredump_seg_header(struct mpi_coredump_segment_header *s
 	seg_hdr->cookie = MPI_COREDUMP_COOKIE;
 	seg_hdr->seg_num = seg_number;
 	seg_hdr->seg_size = seg_size;
-	strncpy(seg_hdr->description, desc, (sizeof(seg_hdr->description)) - 1);
+	strscpy(seg_hdr->description, desc, sizeof(seg_hdr->description));
 }
 
 /*
@@ -737,7 +737,7 @@ int qlge_core_dump(struct qlge_adapter *qdev, struct qlge_mpi_coredump *mpi_core
 		sizeof(struct mpi_coredump_global_header);
 	mpi_coredump->mpi_global_header.image_size =
 		sizeof(struct qlge_mpi_coredump);
-	strncpy(mpi_coredump->mpi_global_header.id_string, "MPI Coredump",
+	strscpy(mpi_coredump->mpi_global_header.id_string, "MPI Coredump",
 		sizeof(mpi_coredump->mpi_global_header.id_string));
 
 	/* Get generic NIC reg dump */
@@ -1225,7 +1225,7 @@ static void qlge_gen_reg_dump(struct qlge_adapter *qdev,
 		sizeof(struct mpi_coredump_global_header);
 	mpi_coredump->mpi_global_header.image_size =
 		sizeof(struct qlge_reg_dump);
-	strncpy(mpi_coredump->mpi_global_header.id_string, "MPI Coredump",
+	strscpy(mpi_coredump->mpi_global_header.id_string, "MPI Coredump",
 		sizeof(mpi_coredump->mpi_global_header.id_string));
 
 	/* segment 16 */
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: qlge: Replace strncpy with strscpy
  2023-10-05 19:14 [PATCH] staging: qlge: Replace strncpy with strscpy Ricardo Lopes
@ 2023-10-06  6:42 ` Dan Carpenter
  2023-10-06  6:49   ` Dan Carpenter
  2023-10-06 13:32 ` Greg KH
  1 sibling, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2023-10-06  6:42 UTC (permalink / raw)
  To: Ricardo Lopes
  Cc: manishc, GR-Linux-NIC-Dev, coiby.xu, gregkh, netdev,
	linux-staging, linux-kernel

On Thu, Oct 05, 2023 at 08:14:55PM +0100, Ricardo Lopes wrote:
> Avoid read overflows and other misbehavior due to missing termination.
> 

There aren't any read overflows in the current code.

> Reported by checkpatch:
> 
> WARNING: Prefer strscpy, strscpy_pad, or __nonstring over strncpy

But making checkpatch happy is good and the patch is fine.

Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: qlge: Replace strncpy with strscpy
  2023-10-06  6:42 ` Dan Carpenter
@ 2023-10-06  6:49   ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2023-10-06  6:49 UTC (permalink / raw)
  To: Ricardo Lopes
  Cc: manishc, GR-Linux-NIC-Dev, coiby.xu, gregkh, netdev,
	linux-staging, linux-kernel

On Fri, Oct 06, 2023 at 09:42:41AM +0300, Dan Carpenter wrote:
> On Thu, Oct 05, 2023 at 08:14:55PM +0100, Ricardo Lopes wrote:
> > Avoid read overflows and other misbehavior due to missing termination.
> > 
> 
> There aren't any read overflows in the current code.
> 

So when you're reviewing these to look for read overflows, a string
literal isn't going to overflow.  So that makes the last two obvious.
But for the first one you have to review the caller qlge_gen_reg_dump()
and the last parameter passed to qlge_build_coredump_seg_header() is
always a string literal so that's obvious too.

It's not really that much work to check for this.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: qlge: Replace strncpy with strscpy
  2023-10-05 19:14 [PATCH] staging: qlge: Replace strncpy with strscpy Ricardo Lopes
  2023-10-06  6:42 ` Dan Carpenter
@ 2023-10-06 13:32 ` Greg KH
  2023-10-06 15:30   ` Ricardo Lopes
  1 sibling, 1 reply; 6+ messages in thread
From: Greg KH @ 2023-10-06 13:32 UTC (permalink / raw)
  To: Ricardo Lopes
  Cc: manishc, GR-Linux-NIC-Dev, coiby.xu, netdev, linux-staging,
	linux-kernel

On Thu, Oct 05, 2023 at 08:14:55PM +0100, Ricardo Lopes wrote:
> Avoid read overflows and other misbehavior due to missing termination.

As Dan said, this is not possible here.  Can you redo the changelog text
and resend it so that people aren't scared by the text?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: qlge: Replace strncpy with strscpy
  2023-10-06 13:32 ` Greg KH
@ 2023-10-06 15:30   ` Ricardo Lopes
  2023-10-06 15:36     ` Dan Carpenter
  0 siblings, 1 reply; 6+ messages in thread
From: Ricardo Lopes @ 2023-10-06 15:30 UTC (permalink / raw)
  To: Greg KH
  Cc: manishc, GR-Linux-NIC-Dev, coiby.xu, netdev, linux-staging,
	linux-kernel

On Fri, Oct 06, 2023 at 03:32:28PM +0200, Greg KH wrote:
> On Thu, Oct 05, 2023 at 08:14:55PM +0100, Ricardo Lopes wrote:
> > Avoid read overflows and other misbehavior due to missing termination.
> 
> As Dan said, this is not possible here.  Can you redo the changelog text
> and resend it so that people aren't scared by the text?

Yes, I suppose removing that sentence and keeping the checkpatch.pl
warning output would do?

Thank you,

Ricardo Lopes

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] staging: qlge: Replace strncpy with strscpy
  2023-10-06 15:30   ` Ricardo Lopes
@ 2023-10-06 15:36     ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2023-10-06 15:36 UTC (permalink / raw)
  To: Ricardo Lopes
  Cc: Greg KH, manishc, GR-Linux-NIC-Dev, coiby.xu, netdev,
	linux-staging, linux-kernel

On Fri, Oct 06, 2023 at 04:30:21PM +0100, Ricardo Lopes wrote:
> On Fri, Oct 06, 2023 at 03:32:28PM +0200, Greg KH wrote:
> > On Thu, Oct 05, 2023 at 08:14:55PM +0100, Ricardo Lopes wrote:
> > > Avoid read overflows and other misbehavior due to missing termination.
> > 
> > As Dan said, this is not possible here.  Can you redo the changelog text
> > and resend it so that people aren't scared by the text?
> 
> Yes, I suppose removing that sentence and keeping the checkpatch.pl
> warning output would do?

Yes.

https://staticthinking.wordpress.com/2022/07/27/how-to-send-a-v2-patch/

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-10-06 15:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-05 19:14 [PATCH] staging: qlge: Replace strncpy with strscpy Ricardo Lopes
2023-10-06  6:42 ` Dan Carpenter
2023-10-06  6:49   ` Dan Carpenter
2023-10-06 13:32 ` Greg KH
2023-10-06 15:30   ` Ricardo Lopes
2023-10-06 15:36     ` Dan Carpenter

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).