提交 cda234ea 编写于 作者: F Fedor Tokarev 提交者: Yang Yingliang

net: sunrpc: Fix off-by-one issues in 'rpc_ntop6'

stable inclusion
from linux-4.19.130
commit 9d9547be1f97ae294e26244ed1b602ec30b5c78d

--------------------------------

[ Upstream commit 118917d6 ]

Fix off-by-one issues in 'rpc_ntop6':
 - 'snprintf' returns the number of characters which would have been
   written if enough space had been available, excluding the terminating
   null byte. Thus, a return value of 'sizeof(scopebuf)' means that the
   last character was dropped.
 - 'strcat' adds a terminating null byte to the string, thus if len ==
   buflen, the null byte is written past the end of the buffer.
Signed-off-by: NFedor Tokarev <ftokarev@gmail.com>
Signed-off-by: NAnna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NLi Aichun <liaichun@huawei.com>
Reviewed-by: Nguodeqing <geffrey.guo@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 5de96355
...@@ -81,11 +81,11 @@ static size_t rpc_ntop6(const struct sockaddr *sap, ...@@ -81,11 +81,11 @@ static size_t rpc_ntop6(const struct sockaddr *sap,
rc = snprintf(scopebuf, sizeof(scopebuf), "%c%u", rc = snprintf(scopebuf, sizeof(scopebuf), "%c%u",
IPV6_SCOPE_DELIMITER, sin6->sin6_scope_id); IPV6_SCOPE_DELIMITER, sin6->sin6_scope_id);
if (unlikely((size_t)rc > sizeof(scopebuf))) if (unlikely((size_t)rc >= sizeof(scopebuf)))
return 0; return 0;
len += rc; len += rc;
if (unlikely(len > buflen)) if (unlikely(len >= buflen))
return 0; return 0;
strcat(buf, scopebuf); strcat(buf, scopebuf);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册