Commit 8c8e2422 authored by Justin Stitt's avatar Justin Stitt Committed by Martin K. Petersen

scsi: mpi3mr: Replace deprecated strncpy() with assignments

Really, there's no bug with the current code. Let's just ditch strncpy()
all together.

We can just copy the const strings instead of reserving room on the stack.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarJustin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20240305-strncpy-drivers-scsi-mpi3mr-mpi3mr_fw-c-v3-1-5b78a13ff984@google.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 16cc2ba7
...@@ -3676,7 +3676,7 @@ static const struct { ...@@ -3676,7 +3676,7 @@ static const struct {
* mpi3mr_print_ioc_info - Display controller information * mpi3mr_print_ioc_info - Display controller information
* @mrioc: Adapter instance reference * @mrioc: Adapter instance reference
* *
* Display controller personalit, capability, supported * Display controller personality, capability, supported
* protocols etc. * protocols etc.
* *
* Return: Nothing * Return: Nothing
...@@ -3685,20 +3685,20 @@ static void ...@@ -3685,20 +3685,20 @@ static void
mpi3mr_print_ioc_info(struct mpi3mr_ioc *mrioc) mpi3mr_print_ioc_info(struct mpi3mr_ioc *mrioc)
{ {
int i = 0, bytes_written = 0; int i = 0, bytes_written = 0;
char personality[16]; const char *personality;
char protocol[50] = {0}; char protocol[50] = {0};
char capabilities[100] = {0}; char capabilities[100] = {0};
struct mpi3mr_compimg_ver *fwver = &mrioc->facts.fw_ver; struct mpi3mr_compimg_ver *fwver = &mrioc->facts.fw_ver;
switch (mrioc->facts.personality) { switch (mrioc->facts.personality) {
case MPI3_IOCFACTS_FLAGS_PERSONALITY_EHBA: case MPI3_IOCFACTS_FLAGS_PERSONALITY_EHBA:
strncpy(personality, "Enhanced HBA", sizeof(personality)); personality = "Enhanced HBA";
break; break;
case MPI3_IOCFACTS_FLAGS_PERSONALITY_RAID_DDR: case MPI3_IOCFACTS_FLAGS_PERSONALITY_RAID_DDR:
strncpy(personality, "RAID", sizeof(personality)); personality = "RAID";
break; break;
default: default:
strncpy(personality, "Unknown", sizeof(personality)); personality = "Unknown";
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment