[libvirt] [PATCH] esx_vmx.c: don't dereference a NULL virtualDev

Matthias Bolte matthias.bolte at googlemail.com
Tue Dec 15 15:43:11 UTC 2009


2009/12/15 Jim Meyering <jim at meyering.net>:
> The offending code starts here:
>
> int
> esxVMX_ParseSCSIController(virConnectPtr conn, virConfPtr conf, int controller,
>                           int *present, char **virtualDev)
> {
>    char present_name[32];
>    char virtualDev_name[32];
>
>    if (virtualDev == NULL || *virtualDev != NULL) {
>        ESX_ERROR(conn, VIR_ERR_INTERNAL_ERROR, "Invalid argument");
>        goto failure;
>    }
>
> If the virtualDev parameter is NULL, then we'd issue the
> diagnostic and take the "goto", and (below), dereference NULL.
>
> >From 79283ba1d667534175d4c48079e6b500feba6480 Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering at redhat.com>
> Date: Tue, 15 Dec 2009 16:07:10 +0100
> Subject: [PATCH] esx_vmx.c: don't dereference NULL for a NULL virtualDev
>
> * src/esx/esx_vmx.c (esxVMX_ParseSCSIController): Don't deref
> "virtualDev" when it is NULL.
> ---
>  src/esx/esx_vmx.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/src/esx/esx_vmx.c b/src/esx/esx_vmx.c
> index f5b4544..404617e 100644
> --- a/src/esx/esx_vmx.c
> +++ b/src/esx/esx_vmx.c
> @@ -1204,7 +1204,8 @@ esxVMX_ParseSCSIController(virConnectPtr conn, virConfPtr conf, int controller,
>     return 0;
>
>   failure:
> -    VIR_FREE(*virtualDev);
> +    if (virtualDev)
> +        VIR_FREE(*virtualDev);
>
>     return -1;
>  }
> --
> 1.6.6.rc2.275.g51e2d
>

This fixes the problem, but I would fix it differently, matching the
other functions. See attached patch.

Matthias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: alternative.diff
Type: text/x-patch
Size: 2044 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20091215/ff8d8efc/attachment-0001.bin>


More information about the libvir-list mailing list