Commit 855ce06f authored by Justin Stitt's avatar Justin Stitt Committed by Martin K. Petersen
Browse files

scsi: wd33c93: Replace deprecated strncpy() with strscpy()



@p1 is assigned to @setup_buffer and then we manually assign a NUL-byte at
the first index. This renders the following strlen() call useless.
Moreover, we don't need to reassign p1 to setup_buffer for any reason --
neither do we need to manually set a NUL-byte at the end. strscpy()
resolves all this code making it easier to read.

Even considering the path where @str is falsey, the manual NUL-byte
assignment is useless as setup_buffer is declared with static storage
duration in the top-level scope which should NUL-initialize the whole
buffer.

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-7-5b78a13ff984@google.com


Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 8fd4c9c8
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -1721,9 +1721,7 @@ wd33c93_setup(char *str)
	p1 = setup_buffer;
	*p1 = '\0';
	if (str)
		strncpy(p1, str, SETUP_BUFFER_SIZE - strlen(setup_buffer));
	setup_buffer[SETUP_BUFFER_SIZE - 1] = '\0';
	p1 = setup_buffer;
		strscpy(p1, str, SETUP_BUFFER_SIZE);
	i = 0;
	while (*p1 && (i < MAX_SETUP_ARGS)) {
		p2 = strchr(p1, ',');