Skip to content

Commit cdcb08d

Browse files
tobluxmartinkpetersen
authored andcommitted
scsi: elx: sli4: Replace deprecated strncpy() with strscpy()
strncpy() is deprecated for NUL-terminated destination buffers; use strscpy() instead. Since sli_config_cmd_init() already zeroes out the destination buffers, the potential NUL-padding by strncpy() is unnecessary. strscpy() copies only the required characters and guarantees NUL-termination. And since all three destination buffers have a fixed length, strscpy() automatically determines their size using sizeof() when the argument is omitted. This makes any explicit sizeof() calls unnecessary. The source strings are also NUL-terminated and meet the __must_be_cstr() requirement of strscpy(). No functional changes intended. Link: KSPP/linux#90 Cc: [email protected] Signed-off-by: Thorsten Blum <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 20c74f8 commit cdcb08d

File tree

1 file changed

+3
-3
lines changed
  • drivers/scsi/elx/libefc_sli

1 file changed

+3
-3
lines changed

drivers/scsi/elx/libefc_sli/sli4.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3804,7 +3804,7 @@ sli_cmd_common_write_object(struct sli4 *sli4, void *buf, u16 noc,
38043804
wr_obj->desired_write_len_dword = cpu_to_le32(dwflags);
38053805

38063806
wr_obj->write_offset = cpu_to_le32(offset);
3807-
strncpy(wr_obj->object_name, obj_name, sizeof(wr_obj->object_name) - 1);
3807+
strscpy(wr_obj->object_name, obj_name);
38083808
wr_obj->host_buffer_descriptor_count = cpu_to_le32(1);
38093809

38103810
bde = (struct sli4_bde *)wr_obj->host_buffer_descriptor;
@@ -3833,7 +3833,7 @@ sli_cmd_common_delete_object(struct sli4 *sli4, void *buf, char *obj_name)
38333833
SLI4_SUBSYSTEM_COMMON, CMD_V0,
38343834
SLI4_RQST_PYLD_LEN(cmn_delete_object));
38353835

3836-
strncpy(req->object_name, obj_name, sizeof(req->object_name) - 1);
3836+
strscpy(req->object_name, obj_name);
38373837
return 0;
38383838
}
38393839

@@ -3856,7 +3856,7 @@ sli_cmd_common_read_object(struct sli4 *sli4, void *buf, u32 desired_read_len,
38563856
cpu_to_le32(desired_read_len & SLI4_REQ_DESIRE_READLEN);
38573857

38583858
rd_obj->read_offset = cpu_to_le32(offset);
3859-
strncpy(rd_obj->object_name, obj_name, sizeof(rd_obj->object_name) - 1);
3859+
strscpy(rd_obj->object_name, obj_name);
38603860
rd_obj->host_buffer_descriptor_count = cpu_to_le32(1);
38613861

38623862
bde = (struct sli4_bde *)rd_obj->host_buffer_descriptor;

0 commit comments

Comments
 (0)