提交 ea7b2a6d 编写于 作者: M Martin Kletzander

util: Fix leak in virStringTrimOptionalNewline

Do not access any data if strlen() == 0.
Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
上级 9baf50c4
......@@ -1394,9 +1394,13 @@ virStringEncodeBase64(const uint8_t *buf, size_t buflen)
*/
void virStringTrimOptionalNewline(char *str)
{
char *tmp = str + strlen(str) - 1;
if (*tmp == '\n')
*tmp = '\0';
size_t len = strlen(str);
if (!len)
return;
if (str[len - 1] == '\n')
str[len - 1] = '\0';
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册