* [PATCH v2] mpi3mr: Fix W=1 compilation warnings
@ 2021-06-29 14:11 Sreekanth Reddy
2021-06-29 20:35 ` Martin K. Petersen
0 siblings, 1 reply; 5+ messages in thread
From: Sreekanth Reddy @ 2021-06-29 14:11 UTC (permalink / raw)
To: linux-scsi, martin.petersen
Cc: jejb, mpi3mr-linuxdrv.pdl, kashyap.desai, sathya.prakash,
Sreekanth Reddy, kernel test robot
[-- Attachment #1: Type: text/plain, Size: 1375 bytes --]
Fix for below W=1 compilation warning,
'strncpy' output may be truncated copying 16 bytes
from a string of length 64
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
---
drivers/scsi/mpi3mr/mpi3mr_fw.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 9eceafca59bc..ede2bd0cf8d4 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -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));
--
2.27.0
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4218 bytes --]
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mpi3mr: Fix W=1 compilation warnings
2021-06-29 14:11 [PATCH v2] mpi3mr: Fix W=1 compilation warnings Sreekanth Reddy
@ 2021-06-29 20:35 ` Martin K. Petersen
2021-07-04 17:09 ` Sreekanth Reddy
0 siblings, 1 reply; 5+ messages in thread
From: Martin K. Petersen @ 2021-06-29 20:35 UTC (permalink / raw)
To: Sreekanth Reddy
Cc: linux-scsi, martin.petersen, jejb, mpi3mr-linuxdrv.pdl,
kashyap.desai, sathya.prakash, kernel test robot
Sreekanth,
> - 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.
> - 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.
> 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.
Thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mpi3mr: Fix W=1 compilation warnings
2021-06-29 20:35 ` Martin K. Petersen
@ 2021-07-04 17:09 ` Sreekanth Reddy
2021-07-06 18:39 ` Martin K. Petersen
0 siblings, 1 reply; 5+ messages in thread
From: Sreekanth Reddy @ 2021-07-04 17:09 UTC (permalink / raw)
To: Martin K. Petersen
Cc: linux-scsi, James E.J. Bottomley, mpi3mr-drvr-developers,
Kashyap Desai, Sathya Prakash Veerichetty, kernel test robot
[-- Attachment #1: Type: text/plain, Size: 1335 bytes --]
On Wed, Jun 30, 2021 at 2:06 AM Martin K. Petersen
<martin.petersen@oracle.com> wrote:
>
>
> Sreekanth,
>
> > - 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);
>
> > - 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.
>
> > 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
>
> Thanks!
>
> --
> Martin K. Petersen Oracle Linux Engineering
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4218 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mpi3mr: Fix W=1 compilation warnings
2021-07-04 17:09 ` Sreekanth Reddy
@ 2021-07-06 18:39 ` Martin K. Petersen
2021-07-07 5:53 ` Sreekanth Reddy
0 siblings, 1 reply; 5+ messages in thread
From: Martin K. Petersen @ 2021-07-06 18:39 UTC (permalink / raw)
To: Sreekanth Reddy
Cc: Martin K. Petersen, linux-scsi, James E.J. Bottomley,
mpi3mr-drvr-developers, Kashyap Desai,
Sathya Prakash Veerichetty, kernel test robot
Sreekanth,
> 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.
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] mpi3mr: Fix W=1 compilation warnings
2021-07-06 18:39 ` Martin K. Petersen
@ 2021-07-07 5:53 ` Sreekanth Reddy
0 siblings, 0 replies; 5+ messages in thread
From: Sreekanth Reddy @ 2021-07-07 5:53 UTC (permalink / raw)
To: Martin K. Petersen
Cc: linux-scsi, James E.J. Bottomley, mpi3mr-drvr-developers,
Kashyap Desai, Sathya Prakash Veerichetty, kernel test robot
[-- Attachment #1: Type: text/plain, Size: 986 bytes --]
On Wed, Jul 7, 2021 at 12:09 AM Martin K. Petersen
<martin.petersen@oracle.com> wrote:
>
>
> Sreekanth,
>
> > 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.
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
>
> --
> Martin K. Petersen Oracle Linux Engineering
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4218 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-07-07 5:54 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-29 14:11 [PATCH v2] mpi3mr: Fix W=1 compilation warnings Sreekanth Reddy
2021-06-29 20:35 ` Martin K. Petersen
2021-07-04 17:09 ` Sreekanth Reddy
2021-07-06 18:39 ` Martin K. Petersen
2021-07-07 5:53 ` Sreekanth Reddy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.