render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
2ba5aa
From 5fe7795d5fa5061f0ba615472f9351f9d29abf48 Mon Sep 17 00:00:00 2001
2ba5aa
Message-Id: <5fe7795d5fa5061f0ba615472f9351f9d29abf48@dist-git>
2ba5aa
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
2ba5aa
Date: Fri, 2 Oct 2020 13:44:44 +0200
2ba5aa
Subject: [PATCH] check for NULL before calling g_regex_unref
2ba5aa
MIME-Version: 1.0
2ba5aa
Content-Type: text/plain; charset=UTF-8
2ba5aa
Content-Transfer-Encoding: 8bit
2ba5aa
2ba5aa
g_regex_unref reports an error if called with a NULL argument.
2ba5aa
2ba5aa
We have two cases in the code where we (possibly) call it on a NULL
2ba5aa
argument. The interesting one is in virDomainQemuMonitorEventCleanup.
2ba5aa
2ba5aa
Based on VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX, we unref
2ba5aa
data->regex, which has two problems:
2ba5aa
2ba5aa
* On the client side, flags is -1 so the comparison is true even if no
2ba5aa
  regex was used, reproducible by:
2ba5aa
  $ virsh qemu-monitor-event --timeout 1
2ba5aa
  which results in an ugly error:
2ba5aa
(process:1289846): GLib-CRITICAL **: 14:58:42.631: g_regex_unref: assertion 'regex != NULL' failed
2ba5aa
* On the server side, we only create the regex if both the flag and the
2ba5aa
  string are present, so it's possible to trigger this message by:
2ba5aa
  $ virsh qemu-monitor-event --regex --timeout 1
2ba5aa
2ba5aa
Use a non-NULL comparison instead of the flag to decide whether we need
2ba5aa
to unref the regex. And add a non-NULL check to the unref in the
2ba5aa
VirtualBox test too.
2ba5aa
2ba5aa
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2ba5aa
Fixes: 71efb59a4de7c51b1bc889a316f1796ebf55738f
2ba5aa
https://bugzilla.redhat.com/show_bug.cgi?id=1876907
2ba5aa
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2ba5aa
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2ba5aa
(cherry picked from commit 92b252456ee6d6ffc6e39e62ce1ce6c50113e00e)
2ba5aa
2ba5aa
https://bugzilla.redhat.com/show_bug.cgi?id=1861176
2ba5aa
2ba5aa
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2ba5aa
Message-Id: <7d3c84f6556d0d46ada037d5e56c831babba609f.1601639064.git.jtomko@redhat.com>
2ba5aa
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2ba5aa
---
2ba5aa
 src/conf/domain_event.c     | 2 +-
2ba5aa
 tests/vboxsnapshotxmltest.c | 3 ++-
2ba5aa
 2 files changed, 3 insertions(+), 2 deletions(-)
2ba5aa
2ba5aa
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
2ba5aa
index 33fbf10406..d3acde0236 100644
2ba5aa
--- a/src/conf/domain_event.c
2ba5aa
+++ b/src/conf/domain_event.c
2ba5aa
@@ -2194,7 +2194,7 @@ virDomainQemuMonitorEventCleanup(void *opaque)
2ba5aa
     virDomainQemuMonitorEventData *data = opaque;
2ba5aa
 
2ba5aa
     VIR_FREE(data->event);
2ba5aa
-    if (data->flags & VIR_CONNECT_DOMAIN_QEMU_MONITOR_EVENT_REGISTER_REGEX)
2ba5aa
+    if (data->regex)
2ba5aa
         g_regex_unref(data->regex);
2ba5aa
     if (data->freecb)
2ba5aa
         (data->freecb)(data->opaque);
2ba5aa
diff --git a/tests/vboxsnapshotxmltest.c b/tests/vboxsnapshotxmltest.c
2ba5aa
index d1a7522931..8577157020 100644
2ba5aa
--- a/tests/vboxsnapshotxmltest.c
2ba5aa
+++ b/tests/vboxsnapshotxmltest.c
2ba5aa
@@ -134,7 +134,8 @@ mymain(void)
2ba5aa
     DO_TEST("2disks-3snap-brother");
2ba5aa
 
2ba5aa
  cleanup:
2ba5aa
-    g_regex_unref(testSnapshotXMLVariableLineRegex);
2ba5aa
+    if (testSnapshotXMLVariableLineRegex)
2ba5aa
+        g_regex_unref(testSnapshotXMLVariableLineRegex);
2ba5aa
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
2ba5aa
 }
2ba5aa
 
2ba5aa
-- 
2ba5aa
2.28.0
2ba5aa