mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-01 17:35:17 +00:00
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: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
e0a4eaa913
commit
3506f1ecfd
@ -795,12 +795,16 @@ virTestCompareToFile(const char *strcontent,
|
|||||||
if (virTestLoadFile(filename, &filecontent) < 0 && !virTestGetRegenerate())
|
if (virTestLoadFile(filename, &filecontent) < 0 && !virTestGetRegenerate())
|
||||||
goto failure;
|
goto failure;
|
||||||
|
|
||||||
if (filecontent &&
|
if (filecontent) {
|
||||||
filecontent[strlen(filecontent) - 1] == '\n' &&
|
size_t filecontentLen = strlen(filecontent);
|
||||||
strcontent[strlen(strcontent) - 1] != '\n') {
|
|
||||||
if (virAsprintf(&fixedcontent, "%s\n", strcontent) < 0)
|
if (filecontentLen > 0 &&
|
||||||
goto failure;
|
filecontent[filecontentLen - 1] == '\n' &&
|
||||||
cmpcontent = fixedcontent;
|
strcontent[strlen(strcontent) - 1] != '\n') {
|
||||||
|
if (virAsprintf(&fixedcontent, "%s\n", strcontent) < 0)
|
||||||
|
goto failure;
|
||||||
|
cmpcontent = fixedcontent;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STRNEQ_NULLABLE(cmpcontent, filecontent)) {
|
if (STRNEQ_NULLABLE(cmpcontent, filecontent)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user