提交 9c75425a 编写于 作者: P Peter Krempa

tests: utils: Fix out-of-bounds access to memory in virTestCompareToFile

Similarly to 3506f1ec, the contents of 'cmpcontent' may be an empty
string so the following code would access memory out of the array.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
上级 c0185331
......@@ -797,10 +797,11 @@ virTestCompareToFile(const char *strcontent,
if (filecontent) {
size_t filecontentLen = strlen(filecontent);
size_t cmpcontentLen = strlen(cmpcontent);
if (filecontentLen > 0 &&
filecontent[filecontentLen - 1] == '\n' &&
cmpcontent[strlen(cmpcontent) - 1] != '\n') {
(cmpcontentLen == 0 || cmpcontent[cmpcontentLen - 1] != '\n')) {
if (virAsprintf(&fixedcontent, "%s\n", cmpcontent) < 0)
goto failure;
cmpcontent = fixedcontent;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册