Skip to contentSkip to conversation

staging: qlge: Replace strncpy with strscpy

PATCH Superseded Ricardo Lopes 3 participants 6 messages Oct 5, 2023 – Oct 6, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: qlge: Replace strncpy with strscpy

Avoid read overflows and other misbehavior due to missing termination.

Reported by checkpatch:

WARNING: Prefer strscpy, strscpy_pad, or __nonstring over strncpy

---
 drivers/staging/qlge/qlge_dbg.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/qlge/qlge_dbg.c +3 -3
index c7e865f51..5f08a8492 100644
@@ -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 */
Signature · 1 line
2.41.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Ricardo Lopes

Avoid read overflows and other misbehavior due to missing termination.

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

Quoted 3 lines

Reported by checkpatch:

WARNING: Prefer strscpy, strscpy_pad, or __nonstring over strncpy

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

regards,
dan carpenter

#2 lore raw
Quoted 6 lines · Dan Carpenter
Quoted 2 lines · Ricardo Lopes

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

maintainer
#3 lore raw
In reply to Ricardo Lopes
Quoted 1 line · Ricardo Lopes

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

#4 lore raw
Quoted 5 lines · Greg KH
Quoted 1 line · Ricardo Lopes

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

#5 lore raw
Quoted 9 lines · Ricardo Lopes
Quoted 5 lines · Greg KH
Quoted 1 line · Ricardo Lopes

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