Re: [PATCH 09/12] esx: avoid dead code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2011/6/6 Eric Blake <eblake@xxxxxxxxxx>:
> Detected by Coverity. ÂThe beginning of the function already filtered
> out NULL objectContentList as invalid; more likely, the code was
> trying to see if esxVI_RetrieveProperties modified *objectContentList.
>
> * src/esx/esx_vi.c (esxVI_LookupObjectContentByType): Check
> correct pointer.
> ---
>
> Matthias, I'm not sure if this is the correct fix, because I don't
> know how escVI_RetrieveProperties is supposed to work.

Sometime one got to love static code analysis tools. Yes, your patch
is correct and necessary :)

esxVI_RetrieveProperties is generated and returns a list of objects
that match the given propertyFilterSpec.
esxVI_LookupObjectContentByType then tests whether the result
corresponds to the expected occurrence and reports an error otherwise.
This simplifies the callers of  esxVI_LookupObjectContentByType, but
due to the missing dereference the check was never performed because
the code thought that at least one item was obtained. NULL represents
an empty list. Your patch now fixes this and is also a potential
segfault fix because callers of esxVI_LookupObjectContentByType that
specified "required" occurrence assume *objectContentList to be
non-NULL when esxVI_LookupObjectContentByType succeeds.

> Âsrc/esx/esx_vi.c | Â Â4 ++--
> Â1 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
> index c5c38ca..64e5b73 100644
> --- a/src/esx/esx_vi.c
> +++ b/src/esx/esx_vi.c
> @@ -2,7 +2,7 @@
> Â/*
> Â* esx_vi.c: client for the VMware VI API 2.5 to manage ESX hosts
> Â*
> - * Copyright (C) 2010 Red Hat, Inc.
> + * Copyright (C) 2010-2011 Red Hat, Inc.
> Â* Copyright (C) 2009-2011 Matthias Bolte <matthias.bolte@xxxxxxxxxxxxxx>
> Â*
> Â* This library is free software; you can redistribute it and/or
> @@ -1737,7 +1737,7 @@ esxVI_LookupObjectContentByType(esxVI_Context *ctx,
> Â Â Â Â goto cleanup;
> Â Â }
>
> - Â Âif (objectContentList == NULL) {
> + Â Âif (*objectContentList == NULL) {
> Â Â Â Â switch (occurrence) {
> Â Â Â Â Â case esxVI_Occurrence_OptionalItem:
> Â Â Â Â Â case esxVI_Occurrence_OptionalList:
>

ACK.

Matthias

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]