mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 19:02:25 +00:00
tests: utils: Fix out-of-bounds access to memory in virTestCompareToFile
Similarly to 3506f1ecfde, the contents of 'cmpcontent' may be an empty string so the following code would access memory out of the array. Signed-off-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
c018533156
commit
9c75425aa2
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user