Skip to contentSkip to conversation

scsi: hpsa: Replace deprecated strncpy() with strscpy_pad()

PATCH Superseded Thorsten Blum 2 participants 3 messages Feb 12, 2025 – Feb 13, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: hpsa: Replace deprecated strncpy() with strscpy_pad()

strncpy() is deprecated for NUL-terminated destination buffers [1].

Replace memset() and strncpy() with strscpy_pad() to copy the version string and fill the remaining bytes in the destination buffer with NUL bytes. This avoids zeroing the memory before copying the string.

Compile-tested only.

---
 drivers/scsi/hpsa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/hpsa.c +1 -2
index 84d8de07b7ae..1334886b68d0 100644
@@ -7238,8 +7238,7 @@ static int hpsa_controller_hard_reset(struct pci_dev *pdev,
 
 static void init_driver_version(char *driver_version, int len)
 {
-	memset(driver_version, 0, len);
-	strncpy(driver_version, HPSA " " HPSA_DRIVER_VERSION, len - 1);
+	strscpy_pad(driver_version, HPSA " " HPSA_DRIVER_VERSION, len - 1);
 }
 
 static int write_driver_ver_to_cfgtable(struct CfgTable __iomem *cfgtable)
Signature · 1 line
2.48.1
#1 lore raw
Quoted 20 lines · On Wed, 12 Feb 2025 23:43:53 +0100 Thorsten Blum <[email protected]>…

strncpy() is deprecated for NUL-terminated destination buffers [1].

Replace memset() and strncpy() with strscpy_pad() to copy the version string and fill the remaining bytes in the destination buffer with NUL bytes. This avoids zeroing the memory before copying the string.

Compile-tested only.

---
 drivers/scsi/hpsa.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/hpsa.c +0 -0
index 84d8de07b7ae..1334886b68d0 100644

drivers/scsi/hpsa.c static int hpsa_controller_hard_reset(struct pci_dev *pdev, · line 7241

Quoted 6 lines
drivers/scsi/hpsa.c +1 -2
@@ -7238,8 +7238,7 @@ static int hpsa_controller_hard_reset(struct pci_dev *pdev,
 
 static void init_driver_version(char *driver_version, int len)
 {
-	memset(driver_version, 0, len);
-	strncpy(driver_version, HPSA " " HPSA_DRIVER_VERSION, len - 1);
+	strscpy_pad(driver_version, HPSA " " HPSA_DRIVER_VERSION, len - 1);

Wrong.
That will truncate maximum length strings.

David

Quoted 3 lines
drivers/scsi/hpsa.c +0 -0
 }
 
 static int write_driver_ver_to_cfgtable(struct CfgTable __iomem *cfgtable)
#2 lore raw
Quoted 11 lines · David Laight
Quoted 8 lines · On Wed, 12 Feb 2025 23:43:53 +0100 Thorsten Blum <[email protected]>…

strncpy() is deprecated for NUL-terminated destination buffers [1].

Replace memset() and strncpy() with strscpy_pad() to copy the version string and fill the remaining bytes in the destination buffer with NUL bytes. This avoids zeroing the memory before copying the string.

Compile-tested only.

Quoted 7 lines
Quoted 4 lines

---

Wrong.
That will truncate maximum length strings.

Yes, I sent a v2 to fix this already.

https://lore.kernel.org/r/[email protected]/

Thanks,
Thorsten