From patchwork Thu Oct 27 19:01:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 122230 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0CA701007D3 for ; Fri, 28 Oct 2011 06:28:52 +1100 (EST) Received: from localhost ([::1]:58001 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJVEl-0005MS-08 for incoming@patchwork.ozlabs.org; Thu, 27 Oct 2011 15:03:35 -0400 Received: from eggs.gnu.org ([140.186.70.92]:44259) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJVEH-0004V8-8p for qemu-devel@nongnu.org; Thu, 27 Oct 2011 15:03:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RJVEA-00024G-Mi for qemu-devel@nongnu.org; Thu, 27 Oct 2011 15:02:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56040) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJVEA-000245-4J for qemu-devel@nongnu.org; Thu, 27 Oct 2011 15:02:58 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9RJ2Pco015227 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 27 Oct 2011 15:02:25 -0400 Received: from localhost (ovpn-113-103.phx2.redhat.com [10.3.113.103]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9RJ2O4t011210; Thu, 27 Oct 2011 15:02:25 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Thu, 27 Oct 2011 17:01:58 -0200 Message-Id: <1319742136-8691-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1319742136-8691-1-git-send-email-lcapitulino@redhat.com> References: <1319742136-8691-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: mdroth@linux.vnet.ibm.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 01/19] qapi-commands.py: Don't call the output marshal on error 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 Today we generate something like this: int qmp_marshal_input_query_foo(...) ... retval = qmp_query_foo(errp); qmp_marshal_output_query_foo(retval, ret, errp); ... However, if qmp_query_foo() fails 'retval' will probably be NULL, which can cause a segfault as not all visitors check if 'retval' is valid. This commit fixes that by changing the code generator to only call the output marshal if qmp_query_foo() succeeds, like this: retval = qmp_query_foo(errp); if (!error_is_set(errp)) { qmp_marshal_output_query_foo(retval, ret, errp); } Signed-off-by: Luiz Capitulino --- scripts/qapi-commands.py | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py index c947ba4..f7def16 100644 --- a/scripts/qapi-commands.py +++ b/scripts/qapi-commands.py @@ -62,7 +62,9 @@ def gen_sync_call(name, args, ret_type, indent=0): name=c_var(name), args=arglist, retval=retval).rstrip() if ret_type: ret += "\n" + mcgen('''' -%(marshal_output_call)s +if (!error_is_set(errp)) { + %(marshal_output_call)s +} ''', marshal_output_call=gen_marshal_output_call(name, ret_type)).rstrip() pop_indent(indent)