提交 3506f1ec 编写于 作者: M Michal Privoznik

virTestCompareToFile: Don't access memory we don't own

After reading the contents of a file some cleanup is performed.
However, the check for it might access a byte outside of the
string - if the file is empty in the first place. Then strlen()
is zero.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 e0a4eaa9
......@@ -795,12 +795,16 @@ virTestCompareToFile(const char *strcontent,
if (virTestLoadFile(filename, &filecontent) < 0 && !virTestGetRegenerate())
goto failure;
if (filecontent &&
filecontent[strlen(filecontent) - 1] == '\n' &&
strcontent[strlen(strcontent) - 1] != '\n') {
if (virAsprintf(&fixedcontent, "%s\n", strcontent) < 0)
goto failure;
cmpcontent = fixedcontent;
if (filecontent) {
size_t filecontentLen = strlen(filecontent);
if (filecontentLen > 0 &&
filecontent[filecontentLen - 1] == '\n' &&
strcontent[strlen(strcontent) - 1] != '\n') {
if (virAsprintf(&fixedcontent, "%s\n", strcontent) < 0)
goto failure;
cmpcontent = fixedcontent;
}
}
if (STRNEQ_NULLABLE(cmpcontent, filecontent)) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册