virtio-serial: don't crash on invalid input
authorMichael S. Tsirkin <mst@redhat.com>
Tue, 22 Mar 2011 16:32:50 +0000 (18:32 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Mon, 28 Mar 2011 16:34:23 +0000 (18:34 +0200)
Fix crash on invalid input in virtio-serial.
Discovered by code review, untested.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/virtio-serial-bus.c

index a82fbe9ba4036dfe7130b6caf188ce4921dbc26e..62273799b6cfaa1b6ab781dd63b05a546467cba1 100644 (file)
@@ -594,6 +594,9 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
 
         id = qemu_get_be32(f);
         port = find_port_by_id(s, id);
+        if (!port) {
+            return -EINVAL;
+        }
 
         port->guest_connected = qemu_get_byte(f);
         host_connected = qemu_get_byte(f);