Skip to content

Commit 5e3d206

Browse files
Hao Chenkuba-moo
authored andcommitted
net: hns3: fix strscpy causing content truncation issue
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 <chenhao418@huawei.com> Signed-off-by: Jijie Shao <shaojijie@huawei.com> Link: https://lore.kernel.org/r/20230809020902.1941471-1-shaojijie@huawei.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 6b48667 commit 5e3d206

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
@@ -464,9 +464,9 @@ static void hns3_dbg_fill_content(char *content, u16 len,
464464
if (result) {
465465
if (item_len < strlen(result[i]))
466466
break;
467-
strscpy(pos, result[i], strlen(result[i]));
467+
memcpy(pos, result[i], strlen(result[i]));
468468
} else {
469-
strscpy(pos, items[i].name, strlen(items[i].name));
469+
memcpy(pos, items[i].name, strlen(items[i].name));
470470
}
471471
pos += item_len;
472472
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
@@ -111,9 +111,9 @@ static void hclge_dbg_fill_content(char *content, u16 len,
111111
if (result) {
112112
if (item_len < strlen(result[i]))
113113
break;
114-
strscpy(pos, result[i], strlen(result[i]));
114+
memcpy(pos, result[i], strlen(result[i]));
115115
} else {
116-
strscpy(pos, items[i].name, strlen(items[i].name));
116+
memcpy(pos, items[i].name, strlen(items[i].name));
117117
}
118118
pos += item_len;
119119
len -= item_len;

0 commit comments

Comments
 (0)