]> git.proxmox.com Git - mirror_qemu.git/commitdiff
hw/i386/vmport: Assert vmport initialized before registering commands
authorLiran Alon <liran.alon@oracle.com>
Thu, 12 Mar 2020 16:54:31 +0000 (18:54 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 10 Jun 2020 16:09:54 +0000 (12:09 -0400)
vmport_register() is also called from other modules such as vmmouse.
Therefore, these modules rely that vmport is realized before those call
sites. If this is violated, vmport_register() will NULL-deref.

To make such issues easier to debug, assert in vmport_register() that
vmport is already realized.

Reviewed-by: Nikita Leshenko <nikita.leshchenko@oracle.com>
Signed-off-by: Liran Alon <liran.alon@oracle.com>
Message-Id: <20200312165431.82118-17-liran.alon@oracle.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/i386/vmport.c

index 309cfd105b17b94c923f229bb2e80c39fae3501b..79ef25d223ade98eb521c1feb74455f9f4222f29 100644 (file)
@@ -81,6 +81,8 @@ static VMPortState *port_state;
 void vmport_register(VMPortCommand command, VMPortReadFunc *func, void *opaque)
 {
     assert(command < VMPORT_ENTRIES);
+    assert(port_state);
+
     trace_vmport_register(command, func, opaque);
     port_state->func[command] = func;
     port_state->opaque[command] = opaque;