From patchwork Wed Jun 12 21:41:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 250912 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1AADC2C0079 for ; Thu, 13 Jun 2013 08:48:46 +1000 (EST) Received: from localhost ([::1]:42377 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UmstJ-0008Ft-Tf for incoming@patchwork.ozlabs.org; Wed, 12 Jun 2013 17:47:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39844) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Umsr0-0005kz-Av for qemu-devel@nongnu.org; Wed, 12 Jun 2013 17:45:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Umsqz-0000yD-Ap for qemu-devel@nongnu.org; Wed, 12 Jun 2013 17:45:18 -0400 Received: from mail-ie0-x230.google.com ([2607:f8b0:4001:c03::230]:55617) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Umsqz-0000xq-6C; Wed, 12 Jun 2013 17:45:17 -0400 Received: by mail-ie0-f176.google.com with SMTP id ar20so22075918iec.21 for ; Wed, 12 Jun 2013 14:45:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=xYkTWD2hsDg0NFpk5xR9OG7XZa/IffUQ7hKyqrDkzgk=; b=e5yQItGQ19DG+DtIxumvmK7RF7XPWgCjRy4S9QnSvqH/swGVcVnvIVgD7wjxOi7EdX lmLToPbuaouCxnYx2T3D8T6mShJQrnZqH68Tstd1dq16PprWSA8k7+IdC1FkrJ2Y9I7q nAV4/Ij+Z61B3z1WS1JfzWIIfdMOROUFbzB0cgIl2C0uJv4Gwhj5WROeb1J3ZKRv9ix7 WmgS0e3kEZt5OxvlSlYmQuvPh508cjzgDIWMKbCloK9KumonXNIiJ+uWlap50Nsi9lzA HhM41sSb8SpeRVkbHI5Ytwvg5ef1O7DyGoMw1L8ZV0cNvKOzj5cEoy3gv0Or1sK0YdFZ 2aTA== X-Received: by 10.42.95.147 with SMTP id f19mr8752531icn.24.1371073516598; Wed, 12 Jun 2013 14:45:16 -0700 (PDT) Received: from localhost ([32.97.110.51]) by mx.google.com with ESMTPSA id ji5sm1000977igb.0.2013.06.12.14.45.15 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 12 Jun 2013 14:45:16 -0700 (PDT) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 12 Jun 2013 16:41:16 -0500 Message-Id: <1371073298-14519-5-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1371073298-14519-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1371073298-14519-1-git-send-email-mdroth@linux.vnet.ibm.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c03::230 Cc: qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH 04/26] qom/object: Don't poll cast cache for NULL objects X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Peter Crosthwaite object_dynamic_cast_assert used to be tolerant of NULL objects and not assert. It's clear from the implementation that this is the expected behavior. The preceding check of the cast cache dereferences obj however causing a segfault. Fix by conditionalizing the cast cache logic on obj being non-null. Signed-off-by: Peter Crosthwaite Reviewed-by: Andreas Färber Reviewed-by: Anthony Liguori Reviewed-by: Paolo Bonzini Reviewed-by: Edgar E. Iglesias Message-id: 8e2bef6a55753869c50bfa32226f7fcf0439ca62.1369183592.git.peter.crosthwaite@xilinx.com Signed-off-by: Anthony Liguori (cherry picked from commit 95916abcf428fb03644468c7fbce64356c6483c0) Signed-off-by: Michael Roth --- qom/object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qom/object.c b/qom/object.c index ec88231..803b94b 100644 --- a/qom/object.c +++ b/qom/object.c @@ -442,7 +442,7 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename, int i; Object *inst; - for (i = 0; i < OBJECT_CLASS_CAST_CACHE; i++) { + for (i = 0; obj && i < OBJECT_CLASS_CAST_CACHE; i++) { if (obj->class->cast_cache[i] == typename) { goto out; } @@ -458,7 +458,7 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename, assert(obj == inst); - if (obj == inst) { + if (obj && obj == inst) { for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) { obj->class->cast_cache[i - 1] = obj->class->cast_cache[i]; }