[PATCH 19/23] Avoid crash on OOM in virbuftest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

The virbuftest code did not check virBufferError before
accessing the buffer contents, resulting in a crash on
OOM conditions.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 tests/virbuftest.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/tests/virbuftest.c b/tests/virbuftest.c
index febe6e4..a6dcae6 100644
--- a/tests/virbuftest.c
+++ b/tests/virbuftest.c
@@ -108,6 +108,10 @@ static int testBufAutoIndent(const void *data ATTRIBUTE_UNUSED)
     }
     virBufferAdjustIndent(buf, 2);
     virBufferAddLit(buf, "1");
+    if (virBufferError(buf)) {
+        TEST_ERROR("Buffer had error");
+        return -1;
+    }
     if (STRNEQ(virBufferCurrentContent(buf), "  1")) {
         TEST_ERROR("Wrong content");
         ret = -1;
@@ -134,6 +138,11 @@ static int testBufAutoIndent(const void *data ATTRIBUTE_UNUSED)
     virBufferEscapeShell(buf, " 11");
     virBufferAddChar(buf, '\n');
 
+    if (virBufferError(buf)) {
+        TEST_ERROR("Buffer had error");
+        return -1;
+    }
+
     result = virBufferContentAndReset(buf);
     if (!result || STRNEQ(result, expected)) {
         virtTestDifference(stderr, expected, result);
@@ -166,6 +175,11 @@ static int testBufTrim(const void *data ATTRIBUTE_UNUSED)
     virBufferTrim(buf, "b,,", 1);
     virBufferTrim(buf, ",", -1);
 
+    if (virBufferError(buf)) {
+        TEST_ERROR("Buffer had error");
+        return -1;
+    }
+
     result = virBufferContentAndReset(buf);
     if (!result || STRNEQ(result, expected)) {
         virtTestDifference(stderr, expected, result);
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]