Skip to contentSkip to conversation

hw/i386/pc: fix possible segment fault for port92_write

PATCH New liguang 1 participant 2 messages Mar 28, 2013

lore
Share & tools
lore

liguang

author
#0 lore raw

PATCH v2 1/2 hw/i386/pc: fix possible segment fault for port92_write

e.g.
$qemu-system-x86_64 -device port92
will report segment fault,
for port92_write try a un-allocated
assignment for a20_out.
so check before this assignment.

---
 hw/i386/pc.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
hw/i386/pc.c +3 -1
index 09fb728..b881314 100644
@@ -444,7 +444,9 @@ static void port92_write(void *opaque, hwaddr addr, uint64_t val,
 
     DPRINTF("port92: write 0x%02x\n", val);
     s->outport = val;
-    qemu_set_irq(*s->a20_out, (val >> 1) & 1);
+    if (s->a20_out) {
+        qemu_set_irq(*s->a20_out, (val >> 1) & 1);
+    }
     if (val & 1) {
         qemu_system_reset_request();
     }
Signature · 1 line
1.7.2.5
author
#1 lore raw

PATCH v2 2/2 hw/i386/pc: check a20_out in port92_realizefn

as suggested by Andreas

---
 hw/i386/pc.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
hw/i386/pc.c +5 -0
index b881314..b0454eb 100644
@@ -503,6 +503,11 @@ static void port92_realizefn(DeviceState *dev, Error **err)
     ISADevice *isadev = ISA_DEVICE(dev);
     Port92State *s = PORT92(dev);
 
+    if (s->a20_out == NULL) {
+        error_setg(err, "Can't create port92 device.\n");
+        return;
+    }
+
     memory_region_init_io(&s->io, &port92_ops, s, "port92", 1);
     isa_register_ioport(isadev, &s->io, 0x92);
 
Signature · 1 line
1.7.2.5