]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: set OOM in virCopyLastError if error is not set
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Mon, 2 Jul 2018 11:16:52 +0000 (14:16 +0300)
committerNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Thu, 19 Jul 2018 07:49:46 +0000 (10:49 +0300)
virCopyLastError is intended to be used after last error is set.
However due to virLastErrorObject failures (very unlikely though
as thread local error is allocated on first use) we can have zero
fields in a copy as a result. In particular code field can be set
to VIR_ERR_OK.

In some places (qemu monitor, qemu agent and qemu migaration code
for example) we use copy result as a flag and this leads to bugs.

Let's set OOM-like error in copy in case of virLastErrorObject failures.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
.gnulib
src/util/virerror.c

diff --git a/.gnulib b/.gnulib
index cdbf3d385a32ff904c96f20c26f3470bd8345248..d6397dde2e127e246e3eeb5254a21f42cac783c8 160000 (submodule)
--- a/.gnulib
+++ b/.gnulib
@@ -1 +1 @@
-Subproject commit cdbf3d385a32ff904c96f20c26f3470bd8345248
+Subproject commit d6397dde2e127e246e3eeb5254a21f42cac783c8
index f198f27957896384f278a5ddd573cc78ba75627b..5f26d5977766219afc5b943fe1178696414679de 100644 (file)
@@ -366,19 +366,26 @@ virSetError(virErrorPtr newerr)
  *
  * One will need to free the result with virResetError()
  *
- * Returns 0 if no error was found and the error code otherwise and -1 in case
- *         of parameter error.
+ * Returns error code or -1 in case of parameter error.
  */
 int
 virCopyLastError(virErrorPtr to)
 {
     virErrorPtr err = virLastErrorObject();
+
+    if (!to)
+        return -1;
+
     /* We can't guarantee caller has initialized it to zero */
     memset(to, 0, sizeof(*to));
-    if (err)
+    if (err) {
         virCopyError(err, to);
-    else
+    } else {
         virResetError(to);
+        to->code = VIR_ERR_NO_MEMORY;
+        to->domain = VIR_FROM_NONE;
+        to->level = VIR_ERR_ERROR;
+    }
     return to->code;
 }