scsi: hpsa: Replace deprecated strncpy() with strscpy_pad()
Subsystems (2)
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
@@ -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
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()andstrncpy()withstrscpy_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.
Link https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]Signed-off-by Thorsten Blum <[email protected]>--- drivers/scsi/hpsa.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/scsi/hpsa.c +0
-0
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)
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()andstrncpy()withstrscpy_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
Link https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]Signed-off-by Thorsten Blum <[email protected]>---
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