Skip to content

Commit d430924

Browse files
committed
scsi: mpi3mr: Avoid possible run-time warning with long manufacturer strings
The prior use of strscpy() here expected the manufacture_reply strings to be NUL-terminated, but it is possible they are not, as the code pattern here shows, e.g., edev->vendor_id being exactly 1 character larger than manufacture_reply->vendor_id, and the strscpy() was copying only up to the size of the source character array. Replace this with memtostr(), which is the unambiguous way to convert a maybe not-NUL-terminated character array into a NUL-terminated string. Fixes: 2bd37e2 ("scsi: mpi3mr: Add framework to issue MPT transport cmds") Reviewed-by: Martin K. Petersen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 5bb288c commit d430924

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

drivers/scsi/mpi3mr/mpi3mr_transport.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,13 @@ static int mpi3mr_report_manufacture(struct mpi3mr_ioc *mrioc,
209209
goto out;
210210
}
211211

212-
strscpy(edev->vendor_id, manufacture_reply->vendor_id,
213-
SAS_EXPANDER_VENDOR_ID_LEN);
214-
strscpy(edev->product_id, manufacture_reply->product_id,
215-
SAS_EXPANDER_PRODUCT_ID_LEN);
216-
strscpy(edev->product_rev, manufacture_reply->product_rev,
217-
SAS_EXPANDER_PRODUCT_REV_LEN);
212+
memtostr(edev->vendor_id, manufacture_reply->vendor_id);
213+
memtostr(edev->product_id, manufacture_reply->product_id);
214+
memtostr(edev->product_rev, manufacture_reply->product_rev);
218215
edev->level = manufacture_reply->sas_format & 1;
219216
if (edev->level) {
220-
strscpy(edev->component_vendor_id,
221-
manufacture_reply->component_vendor_id,
222-
SAS_EXPANDER_COMPONENT_VENDOR_ID_LEN);
217+
memtostr(edev->component_vendor_id,
218+
manufacture_reply->component_vendor_id);
223219
tmp = (u8 *)&manufacture_reply->component_id;
224220
edev->component_id = tmp[0] << 8 | tmp[1];
225221
edev->component_revision_id =

0 commit comments

Comments
 (0)