Skip to contentSkip to conversation

scsi: lpfc: Fix gcc -Wstringop-overread warning, again

PATCH Applied Arnd Bergmann 3 participants 3 messages Sep 20, 2021 – Sep 22, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: lpfc: Fix gcc -Wstringop-overread warning, again

From: Arnd Bergmann <[email protected]>

I fixed a stringop-overread warning earlier this year, now a second copy of the original code was added and the warning came back:

drivers/scsi/lpfc/lpfc_attr.c: In function 'lpfc_cmf_info_show':
drivers/scsi/lpfc/lpfc_attr.c:289:25: error: 'strnlen' specified bound 4095 exceeds source size 24 [-Werror=stringop-overread]

  289 |                         strnlen(LPFC_INFO_MORE_STR, PAGE_SIZE - 1),
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix it the same way as the other copy.

Fixes ada48ba70f6b ("scsi: lpfc: Fix gcc -Wstringop-overread warning")
Fixes 74a7baa2a3ee ("scsi: lpfc: Add cmf_info sysfs entry")
---
 drivers/scsi/lpfc/lpfc_attr.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/scsi/lpfc/lpfc_attr.c +2 -5
index b35bf70a8c0d..ca0433e28ac3 100644
@@ -285,11 +285,8 @@ lpfc_cmf_info_show(struct device *dev, struct device_attribute *attr,
 				"6312 Catching potential buffer "
 				"overflow > PAGE_SIZE = %lu bytes\n",
 				PAGE_SIZE);
-		strscpy(buf + PAGE_SIZE - 1 -
-			strnlen(LPFC_INFO_MORE_STR, PAGE_SIZE - 1),
-			LPFC_INFO_MORE_STR,
-			strnlen(LPFC_INFO_MORE_STR, PAGE_SIZE - 1)
-			+ 1);
+		strscpy(buf + PAGE_SIZE - 1 - sizeof(LPFC_INFO_MORE_STR),
+			LPFC_INFO_MORE_STR, sizeof(LPFC_INFO_MORE_STR) + 1);
 	}
 	return len;
 }
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

I fixed a stringop-overread warning earlier this year, now a second copy of the original code was added and the warning came back:

drivers/scsi/lpfc/lpfc_attr.c: In function 'lpfc_cmf_info_show':
drivers/scsi/lpfc/lpfc_attr.c:289:25: error: 'strnlen' specified bound 4095 exceeds source size 24 [-Werror=stringop-overread]

   289 |                         strnlen(LPFC_INFO_MORE_STR, PAGE_SIZE - 1),
       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 7 lines

Fix it the same way as the other copy.

Fixes ada48ba70f6b ("scsi: lpfc: Fix gcc -Wstringop-overread warning")
Fixes 74a7baa2a3ee ("scsi: lpfc: Add cmf_info sysfs entry")
---
  drivers/scsi/lpfc/lpfc_attr.c | 7 ++-----

Thank You Arnd. Looks good.

-- james

#2 lore raw
In reply to Arnd Bergmann
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

I fixed a stringop-overread warning earlier this year, now a second copy of the original code was added and the warning came back:

Quoted 6 lines

drivers/scsi/lpfc/lpfc_attr.c: In function 'lpfc_cmf_info_show':
drivers/scsi/lpfc/lpfc_attr.c:289:25: error: 'strnlen' specified bound 4095 exceeds source size 24 [-Werror=stringop-overread]

  289 |                         strnlen(LPFC_INFO_MORE_STR, PAGE_SIZE - 1),
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

[...]

Applied to 5.15/scsi-fixes, thanks!

[1/1] scsi: lpfc: Fix gcc -Wstringop-overread warning, again

      https://git.kernel.org/mkp/scsi/c/a38923f2d088
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering