[libvirt] [PATCH] Fix potential crash in QEMU monitor JSON impl

Daniel Veillard veillard at redhat.com
Mon Jul 12 13:21:54 UTC 2010


On Mon, Jul 12, 2010 at 02:08:18PM +0100, Daniel P. Berrange wrote:
> An indentation mistake meant that a check for return status
> was not properly performed in all cases. This could result
> in a crash on NULL pointer in a following line.
> 
> * src/qemu/qemu_monitor_json.c: Fix check for return status
>   when processing JSON for blockstats
> ---
>  src/qemu/qemu_monitor_json.c |   15 ++++++++-------
>  1 files changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index 01be86d..4487ff5 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -1059,11 +1059,10 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon,
>  
>      ret = qemuMonitorJSONCommand(mon, cmd, &reply);
>  
> -    if (ret == 0) {
> +    if (ret == 0)
>          ret = qemuMonitorJSONCheckError(cmd, reply);
> -        if (ret < 0)
> -            goto cleanup;
> -    }
> +    if (ret < 0)
> +        goto cleanup;
>      ret = -1;
>  
>      devices = virJSONValueObjectGet(reply, "return");
> @@ -1164,11 +1163,13 @@ int qemuMonitorJSONGetBlockExtent(qemuMonitorPtr mon,
>      if (!cmd)
>          return -1;
>  
> -    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
> -        goto cleanup;
> +    ret = qemuMonitorJSONCommand(mon, cmd, &reply);
>  
> -    if (qemuMonitorJSONCheckError(cmd, reply) < 0)
> +    if (ret == 0)
> +        ret = qemuMonitorJSONCheckError(cmd, reply);
> +    if (ret < 0)
>          goto cleanup;
> +    ret = -1;
>  
>      devices = virJSONValueObjectGet(reply, "return");
>      if (!devices || devices->type != VIR_JSON_TYPE_ARRAY) {

  Ah right, ACK to the two fixes.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list