mpi3mr: Fix W=1 compilation warnings
Subsystems (2)
Sreekanth Reddy
maintainerPATCH v2 1/1 mpi3mr: Fix W=1 compilation warnings
Fix for below W=1 compilation warning, 'strncpy' output may be truncated copying 16 bytes
from a string of length 64
--- drivers/scsi/mpi3mr/mpi3mr_fw.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/mpi3mr/mpi3mr_fw.c +2 -2
@@ -2608,9 +2608,9 @@ static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc) } drv_info->information_length =cpu_to_le32 (data_len);strncpy (drv_info->driver_signature,"Broadcom" ,sizeof (drv_info->driver_signature)); -strncpy (drv_info->os_name,utsname ()->sysname,sizeof (drv_info->os_name)); +strscpy (drv_info->os_name,utsname ()->sysname,sizeof (drv_info->os_name)); drv_info->os_name[sizeof (drv_info->os_name) -1 ] =0 ; -strncpy (drv_info->os_version,utsname ()->release,sizeof (drv_info->os_version)); +strscpy (drv_info->os_version,utsname ()->release,sizeof (drv_info->os_version)); drv_info->os_version[sizeof (drv_info->os_version) -1 ] =0 ;strncpy (drv_info->driver_name,MPI3MR_DRIVER_NAME ,sizeof (drv_info->driver_name));strncpy (drv_info->driver_version,MPI3MR_DRIVER_VERSION ,sizeof (drv_info->driver_version));
Signature · 1 line
2.27.0
Sreekanth,
drivers/scsi/mpi3mr/mpi3mr_fw.c static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc) · line 2612
Quoted 3 lines
drivers/scsi/mpi3mr/mpi3mr_fw.c +1
-1-strncpy (drv_info->os_name,utsname ()->sysname,sizeof (drv_info->os_name)); +strscpy (drv_info->os_name,utsname ()->sysname,sizeof (drv_info->os_name)); drv_info->os_name[sizeof (drv_info->os_name) -1 ] =0 ;
strscpy() terminates the string.
drivers/scsi/mpi3mr/mpi3mr_fw.c static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc) · line 2614
Quoted 3 lines
drivers/scsi/mpi3mr/mpi3mr_fw.c +1
-1-strncpy (drv_info->os_version,utsname ()->release,sizeof (drv_info->os_version)); +strscpy (drv_info->os_version,utsname ()->release,sizeof (drv_info->os_version)); drv_info->os_version[sizeof (drv_info->os_version) -1 ] =0 ;
Same here.
drivers/scsi/mpi3mr/mpi3mr_fw.c static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc) · line 2616
Quoted 2 lines
drivers/scsi/mpi3mr/mpi3mr_fw.c +0
-0strncpy (drv_info->driver_name,MPI3MR_DRIVER_NAME ,sizeof (drv_info->driver_name));strncpy (drv_info->driver_version,MPI3MR_DRIVER_VERSION ,sizeof (drv_info->driver_version));
Please convert the remaining strncpy() calls as well.
Thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Sreekanth Reddy
maintainerQuoted 9 lines · Martin K. Petersen
Sreekanth,
drivers/scsi/mpi3mr/mpi3mr_fw.c static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc) · line 2612
Quoted 3 lines
drivers/scsi/mpi3mr/mpi3mr_fw.c +1
-1-strncpy (drv_info->os_name,utsname ()->sysname,sizeof (drv_info->os_name)); +strscpy (drv_info->os_name,utsname ()->sysname,sizeof (drv_info->os_name)); drv_info->os_name[sizeof (drv_info->os_name) -1 ] =0 ;
strscpy()terminates the string.
I verified strscpy() is not adding any null terminator when source string length is greater than destination buffer size. And we need the string to be null terminated. or Can I replace it as strscpy(drv_info->os_name, utsname()->sysname, sizeof(drv_info->os_name) -1);
Quoted 11 lines
drivers/scsi/mpi3mr/mpi3mr_fw.c static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc) · line 2614
Quoted 4 lines
drivers/scsi/mpi3mr/mpi3mr_fw.c +1
-1-strncpy (drv_info->os_version,utsname ()->release,sizeof (drv_info->os_version)); +strscpy (drv_info->os_version,utsname ()->release,sizeof (drv_info->os_version)); drv_info->os_version[sizeof (drv_info->os_version) -1 ] =0 ;Same here.
Quoted 2 lines
strncpy(drv_info->driver_name, MPI3MR_DRIVER_NAME, sizeof(drv_info->driver_name)); strncpy(drv_info->driver_version, MPI3MR_DRIVER_VERSION, sizeof(drv_info->driver_version));Please convert the remaining
strncpy()calls as well.
Sure. I will replace strncpy() with strscpy() in the next update patch.
Thanks,
Sreekanth
Quoted 5 lines
Thanks!
--
Martin K. Petersen Oracle Linux Engineering
Sreekanth,
Quoted 2 lines
I verified
strscpy()is not adding any null terminator when source string length is greater than destination buffer size.
That's odd. The point of strscpy() is that it guarantees termination:
---8<---
/**
* strscpy - Copy a C-string into a sized buffer
* @dest: Where to copy the string to
* @src: Where to copy the string from
* @count: Size of destination buffer
*
* Copy the string, or as much of it as fits, into the dest buffer. The
* behavior is undefined if the string buffers overlap. The destination
* buffer is always NUL terminated, unless it's zero-sized.
---8<---
I tested it and it works fine for me.
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering
Sreekanth Reddy
maintainerQuoted 21 lines · Martin K. Petersen
Sreekanth,
Quoted 2 lines
I verified
strscpy()is not adding any null terminator when source string length is greater than destination buffer size.That's odd. The point of
strscpy()is that it guarantees termination:---8<---
/**
* strscpy - Copy a C-string into a sized buffer
* @dest: Where to copy the string to
* @src: Where to copy the string from
* @count: Size of destination buffer
*
* Copy the string, or as much of it as fits, into the dest buffer. The
* behavior is undefined if the string buffers overlap. The destination
* buffer is always NUL terminated, unless it's zero-sized.
---8<---
Quoted 1 line
I tested it and it works fine for me.
Ok, my bad. I made a small mistake while verifying it. Now I rectified it and saw that strscpy() is adding a NULL character at the end.
Thanks,
Sreekanth
Quoted 3 lines
--
Martin K. Petersen Oracle Linux Engineering