pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size()
QEMU will crash when device-memory-region-size property is read if ms->device_memory wasn't initialized yet. Crash can be reproduced with: $QEMU -preconfig -qmp unix:qmp_socket,server,nowait & ./scripts/qmp/qom-get -s qmp_socket /machine.device-memory-region-size Instead of crashing return 0 if ms->device_memory hasn't been initialized. Signed-off-by: Igor Mammedov <imammedo@redhat.com> Message-Id: <20190624090200.5383-1-imammedo@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
parent
d65af288a8
commit
fc3b77e20d
@ -2553,7 +2553,11 @@ pc_machine_get_device_memory_region_size(Object *obj, Visitor *v,
|
||||
Error **errp)
|
||||
{
|
||||
MachineState *ms = MACHINE(obj);
|
||||
int64_t value = memory_region_size(&ms->device_memory->mr);
|
||||
int64_t value = 0;
|
||||
|
||||
if (ms->device_memory) {
|
||||
value = memory_region_size(&ms->device_memory->mr);
|
||||
}
|
||||
|
||||
visit_type_int(v, name, &value, errp);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user