Skip to content

Commit c4f7de3

Browse files
Hao Chengregkh
authored andcommitted
net: hns3: fix strscpy causing content truncation issue
commit 5e3d206 upstream. hns3_dbg_fill_content()/hclge_dbg_fill_content() is aim to integrate some items to a string for content, and we add '\n' and '\0' in the last two bytes of content. strscpy() will add '\0' in the last byte of destination buffer(one of items), it result in finishing content print ahead of schedule and some dump content truncation. One Error log shows as below: cat mac_list/uc UC MAC_LIST: Expected: UC MAC_LIST: FUNC_ID MAC_ADDR STATE pf 00:2b:19:05:03:00 ACTIVE The destination buffer is length-bounded and not required to be NUL-terminated, so just change strscpy() to memcpy() to fix it. Fixes: 1cf3d55 ("net: hns3: fix strncpy() not using dest-buf length as length issue") Signed-off-by: Hao Chen <[email protected]> Signed-off-by: Jijie Shao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 87d7e14 commit c4f7de3

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3_debugfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,9 @@ static void hns3_dbg_fill_content(char *content, u16 len,
458458
if (result) {
459459
if (item_len < strlen(result[i]))
460460
break;
461-
strscpy(pos, result[i], strlen(result[i]));
461+
memcpy(pos, result[i], strlen(result[i]));
462462
} else {
463-
strscpy(pos, items[i].name, strlen(items[i].name));
463+
memcpy(pos, items[i].name, strlen(items[i].name));
464464
}
465465
pos += item_len;
466466
len -= item_len;

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ static void hclge_dbg_fill_content(char *content, u16 len,
110110
if (result) {
111111
if (item_len < strlen(result[i]))
112112
break;
113-
strscpy(pos, result[i], strlen(result[i]));
113+
memcpy(pos, result[i], strlen(result[i]));
114114
} else {
115-
strscpy(pos, items[i].name, strlen(items[i].name));
115+
memcpy(pos, items[i].name, strlen(items[i].name));
116116
}
117117
pos += item_len;
118118
len -= item_len;

0 commit comments

Comments
 (0)