[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v2] pc: fix possible NULL pointer dereference in
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [Qemu-devel] [PATCH v2] pc: fix possible NULL pointer dereference in pc_machine_get_device_memory_region_size() |
Date: |
Tue, 25 Jun 2019 12:17:10 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 |
On 6/24/19 11:02 AM, Igor Mammedov wrote:
> 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 <address@hidden>
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
> ---
>
> v2:
> * fix missing return value assignment
> (Eduardo Habkost <address@hidden>)
> ---
> hw/i386/pc.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index e96360b47a..552f3401e2 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -2458,7 +2458,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);
> }
>