]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virQEMUCapsNewBinary: Avoid NULL dereference
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 30 Mar 2020 08:56:08 +0000 (10:56 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 30 Mar 2020 14:14:11 +0000 (16:14 +0200)
Even with GLib it is still possible for virQEMUCapsNew() to
return NULL because it calls virQEMUCapsInitialize() which is a
wrapper over pthread_once() which may fail. At least, we still
check for its retval. If it so happens that the virQEMUCapsNew()
fails and returns NULL, we should not dereference it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/qemu/qemu_capabilities.c

index a95a60c36ab04803f0f878cebe21f801723347ef..3afe8a7b2c3bd97ad4e67a4e701d9284c4d37738 100644 (file)
@@ -1713,7 +1713,8 @@ virQEMUCapsNewBinary(const char *binary)
 {
     virQEMUCapsPtr qemuCaps = virQEMUCapsNew();
 
-    qemuCaps->binary = g_strdup(binary);
+    if (qemuCaps)
+        qemuCaps->binary = g_strdup(binary);
 
     return qemuCaps;
 }