From patchwork Mon Oct 24 13:26:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 121347 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 66240B6F9B for ; Tue, 25 Oct 2011 00:27:53 +1100 (EST) Received: from localhost ([::1]:34421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIKZC-0000bk-Ba for incoming@patchwork.ozlabs.org; Mon, 24 Oct 2011 09:27:50 -0400 Received: from eggs.gnu.org ([140.186.70.92]:44028) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIKYq-0000SL-3Z for qemu-devel@nongnu.org; Mon, 24 Oct 2011 09:27:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RIKYk-0003XV-LT for qemu-devel@nongnu.org; Mon, 24 Oct 2011 09:27:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RIKYk-0003Vo-9u for qemu-devel@nongnu.org; Mon, 24 Oct 2011 09:27:22 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9ODRJ6X026657 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 24 Oct 2011 09:27:19 -0400 Received: from localhost (ovpn-113-89.phx2.redhat.com [10.3.113.89]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9ODRI6Y007088; Mon, 24 Oct 2011 09:27:19 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Mon, 24 Oct 2011 11:26:54 -0200 Message-Id: <1319462832-12199-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1319462832-12199-1-git-send-email-lcapitulino@redhat.com> References: <1319462832-12199-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, armbru@redhat.com, aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, quintela@redhat.com 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)