Commit 5e3d2061 authored by Hao Chen's avatar Hao Chen Committed by Jakub Kicinski

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: 1cf3d556 ("net: hns3: fix strncpy() not using dest-buf length as length issue")
Signed-off-by: default avatarHao Chen <chenhao418@huawei.com>
Signed-off-by: default avatarJijie Shao <shaojijie@huawei.com>
Link: https://lore.kernel.org/r/20230809020902.1941471-1-shaojijie@huawei.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 6b486676
...@@ -464,9 +464,9 @@ static void hns3_dbg_fill_content(char *content, u16 len, ...@@ -464,9 +464,9 @@ static void hns3_dbg_fill_content(char *content, u16 len,
if (result) { if (result) {
if (item_len < strlen(result[i])) if (item_len < strlen(result[i]))
break; break;
strscpy(pos, result[i], strlen(result[i])); memcpy(pos, result[i], strlen(result[i]));
} else { } else {
strscpy(pos, items[i].name, strlen(items[i].name)); memcpy(pos, items[i].name, strlen(items[i].name));
} }
pos += item_len; pos += item_len;
len -= item_len; len -= item_len;
......
...@@ -111,9 +111,9 @@ static void hclge_dbg_fill_content(char *content, u16 len, ...@@ -111,9 +111,9 @@ static void hclge_dbg_fill_content(char *content, u16 len,
if (result) { if (result) {
if (item_len < strlen(result[i])) if (item_len < strlen(result[i]))
break; break;
strscpy(pos, result[i], strlen(result[i])); memcpy(pos, result[i], strlen(result[i]));
} else { } else {
strscpy(pos, items[i].name, strlen(items[i].name)); memcpy(pos, items[i].name, strlen(items[i].name));
} }
pos += item_len; pos += item_len;
len -= item_len; len -= item_len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment