Commit 5bb288c4 authored by Kees Cook's avatar Kees Cook
Browse files

scsi: mptfusion: Avoid possible run-time warning with long manufacturer strings



The prior strscpy() replacement of strncpy() 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 replaced strncpy() 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.

Reported-by: default avatarCharles Bertsch <cbertsch@cox.net>
Closes: https://lore.kernel.org/all/5445ba0f-3e27-4d43-a9ba-0cc22ada2fce@cox.net/


Fixes: 45e833f0 ("scsi: message: fusion: Replace deprecated strncpy() with strscpy()")
Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20240410023155.2100422-2-keescook@chromium.org


Signed-off-by: default avatarKees Cook <keescook@chromium.org>
parent f700b719
Loading
Loading
Loading
Loading
+5 −9
Original line number Diff line number Diff line
@@ -2964,17 +2964,13 @@ mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc,
			goto out_free;

		manufacture_reply = data_out + sizeof(struct rep_manu_request);
		strscpy(edev->vendor_id, manufacture_reply->vendor_id,
			sizeof(edev->vendor_id));
		strscpy(edev->product_id, manufacture_reply->product_id,
			sizeof(edev->product_id));
		strscpy(edev->product_rev, manufacture_reply->product_rev,
			sizeof(edev->product_rev));
		memtostr(edev->vendor_id, manufacture_reply->vendor_id);
		memtostr(edev->product_id, manufacture_reply->product_id);
		memtostr(edev->product_rev, manufacture_reply->product_rev);
		edev->level = manufacture_reply->sas_format;
		if (manufacture_reply->sas_format) {
			strscpy(edev->component_vendor_id,
				manufacture_reply->component_vendor_id,
				sizeof(edev->component_vendor_id));
			memtostr(edev->component_vendor_id,
				 manufacture_reply->component_vendor_id);
			tmp = (u8 *)&manufacture_reply->component_id;
			edev->component_id = tmp[0] << 8 | tmp[1];
			edev->component_revision_id =