Skip to contentSkip to conversation

bnxt_en: Fix strcpy() warnings in bnxt_ethtool.c

PATCH Applied Michael Chan 2 participants 4 messages Aug 10, 2018 – Aug 11, 2018

Subsystems (3)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore

Michael Chan

author maintainer
#0 lore raw

PATCH 1/1 bnxt_en: Fix strcpy() warnings in bnxt_ethtool.c

From: Vasundhara Volam <[email protected]>

This patch fixes following smatch warnings:

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2826 bnxt_fill_coredump_seg_hdr() error: strcpy() '"sEgM"' too large for 'seg_hdr->signature' (5 vs 4) drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2858 bnxt_fill_coredump_record() error: strcpy() '"cOrE"' too large for 'record->signature' (5 vs 4) drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2879 bnxt_fill_coredump_record() error: strcpy() 'utsname()->sysname' too large for 'record->os_name' (65 vs 32)

Fixes 6c5657d085ae ("bnxt_en: Add support for ethtool get dump.")
---
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +3 -3
index b6dbc3f..d6f3289 100644
@@ -2823,7 +2823,7 @@ bnxt_fill_coredump_seg_hdr(struct bnxt *bp,
 			   int status, u32 duration, u32 instance)
 {
 	memset(seg_hdr, 0, sizeof(*seg_hdr));
-	strcpy(seg_hdr->signature, "sEgM");
+	memcpy(seg_hdr->signature, "sEgM", 4);
 	if (seg_rec) {
 		seg_hdr->component_id = (__force __le32)seg_rec->component_id;
 		seg_hdr->segment_id = (__force __le32)seg_rec->segment_id;
@@ -2855,7 +2855,7 @@ bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record,
 
 	time64_to_tm(start, 0, &tm);
 	memset(record, 0, sizeof(*record));
-	strcpy(record->signature, "cOrE");
+	memcpy(record->signature, "cOrE", 4);
 	record->flags = 0;
 	record->low_version = 0;
 	record->high_version = 1;
@@ -2876,7 +2876,7 @@ bnxt_fill_coredump_record(struct bnxt *bp, struct bnxt_coredump_record *record,
 	record->os_ver_major = cpu_to_le32(os_ver_major);
 	record->os_ver_minor = cpu_to_le32(os_ver_minor);
 
-	strcpy(record->os_name, utsname()->sysname);
+	strncpy(record->os_name, utsname()->sysname, 32);
 	time64_to_tm(end, 0, &tm);
 	record->end_year = cpu_to_le16(tm.tm_year + 1900);
 	record->end_month = cpu_to_le16(tm.tm_mon + 1);
Signature · 1 line
2.5.1
maintainer Applied
#1 lore raw

From: Michael Chan <[email protected]>
Date: Fri, 10 Aug 2018 17:02:12 -0400

Quoted 4 lines

From: Vasundhara Volam <[email protected]>

This patch fixes following smatch warnings:

Quoted 8 lines

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2826 bnxt_fill_coredump_seg_hdr() error: strcpy() '"sEgM"' too large for 'seg_hdr->signature' (5 vs 4) drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2858 bnxt_fill_coredump_record() error: strcpy() '"cOrE"' too large for 'record->signature' (5 vs 4) drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2879 bnxt_fill_coredump_record() error: strcpy() 'utsname()->sysname' too large for 'record->os_name' (65 vs 32)

Fixes 6c5657d085ae ("bnxt_en: Add support for ethtool get dump.")

Applied, thanks Michael.

maintainer
#2 lore raw

From: David Miller <[email protected]>
Date: Fri, 10 Aug 2018 14:35:45 -0700 (PDT)

Quoted 11 lines

From: Michael Chan <[email protected]>
Date: Fri, 10 Aug 2018 17:02:12 -0400

Quoted 8 lines

From: Vasundhara Volam <[email protected]>

This patch fixes following smatch warnings:

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2826 bnxt_fill_coredump_seg_hdr() error: strcpy() '"sEgM"' too large for 'seg_hdr->signature' (5 vs 4) drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2858 bnxt_fill_coredump_record() error: strcpy() '"cOrE"' too large for 'record->signature' (5 vs 4) drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2879 bnxt_fill_coredump_record() error: strcpy() 'utsname()->sysname' too large for 'record->os_name' (65 vs 32)

Quoted 6 lines
Quoted 4 lines
Fixes 6c5657d085ae ("bnxt_en: Add support for ethtool get dump.")

Applied, thanks Michael.

Actually, I'm reverting, this may fix those three warnings, but they are replaced with a new one:

./include/linux/string.h:246:9: warning: ‘__builtin_strncpy’ output may be truncated copying 32 bytes from a string of length 64 [-Wstringop-truncation]

Sorry.

author maintainer
#3 lore raw
Quoted 19 lines · David Miller

From: David Miller <[email protected]>
Date: Fri, 10 Aug 2018 14:35:45 -0700 (PDT)

Quoted 16 lines

From: Michael Chan <[email protected]>
Date: Fri, 10 Aug 2018 17:02:12 -0400

Quoted 12 lines

From: Vasundhara Volam <[email protected]>

This patch fixes following smatch warnings:

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2826 bnxt_fill_coredump_seg_hdr() error: strcpy() '"sEgM"' too large for 'seg_hdr->signature' (5 vs 4) drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2858 bnxt_fill_coredump_record() error: strcpy() '"cOrE"' too large for 'record->signature' (5 vs 4) drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c:2879 bnxt_fill_coredump_record() error: strcpy() 'utsname()->sysname' too large for 'record->os_name' (65 vs 32)

Fixes 6c5657d085ae ("bnxt_en: Add support for ethtool get dump.")
Quoted 7 lines
Quoted 1 line

Applied, thanks Michael.

Actually, I'm reverting, this may fix those three warnings, but they are replaced with a new one:

./include/linux/string.h:246:9: warning: ‘__builtin_strncpy’ output may be truncated copying 32 bytes from a string of length 64 [-Wstringop-truncation]

OK. I'm guessing strlcpy() is the right variant to use here. I will repost v2 using strlcpy(). Thanks.