From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56944) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uosbo-0002RT-83 for qemu-devel@nongnu.org; Tue, 18 Jun 2013 05:53:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uosbl-0000RM-VB for qemu-devel@nongnu.org; Tue, 18 Jun 2013 05:53:52 -0400 Message-ID: <51C02E26.604@redhat.com> Date: Tue, 18 Jun 2013 11:53:42 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <94cd5ba46b74eea289a7e582635820c1c54e66fa.1371546907.git.peter.crosthwaite@xilinx.com> In-Reply-To: <94cd5ba46b74eea289a7e582635820c1c54e66fa.1371546907.git.peter.crosthwaite@xilinx.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v1 1/1] qom: Fix class cast of NULL classes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: peter.crosthwaite@xilinx.com Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org, "1.5.x" Il 18/06/2013 11:18, peter.crosthwaite@xilinx.com ha scritto: > From: Peter Crosthwaite > > Its clear from the implementation that class casting is supposed to work > with a NULL class argument. Guard all dereferences of the class argument > against NULL accordingly. > > Signed-off-by: Peter Crosthwaite Cc: qemu-stable@nongnu.org > --- > > qom/object.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/qom/object.c b/qom/object.c > index 803b94b..b7ecb9f 100644 > --- a/qom/object.c > +++ b/qom/object.c > @@ -531,14 +531,14 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class, > #ifdef CONFIG_QOM_CAST_DEBUG > int i; > > - for (i = 0; i < OBJECT_CLASS_CAST_CACHE; i++) { > + for (i = 0; class && i < OBJECT_CLASS_CAST_CACHE; i++) { > if (class->cast_cache[i] == typename) { > ret = class; > goto out; > } > } > #else > - if (!class->interfaces) { > + if (!class || !class->interfaces) { > return class; > } > #endif > @@ -551,7 +551,7 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class, > } > > #ifdef CONFIG_QOM_CAST_DEBUG > - if (ret == class) { > + if (class && ret == class) { > for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) { > class->cast_cache[i - 1] = class->cast_cache[i]; > } >